Переглянути джерело

uthash.h: fix compiler warning -Wcast-qual

The macro HASH_ADD_KEYPTR_BYHASHVALUE casts keyptr to (char *) hence
violating const keys. As the key is used read-only, the UT_hash_handle
structure can be changed to const void *key, allowing the cast to
(const void *) instead.

This fixes compiler warnings emitted when -Wcast-qual is specified.
Olaf Bergmann 5 роки тому
батько
коміт
0831d9a087
1 змінених файлів з 2 додано та 2 видалено
  1. 2 2
      src/uthash.h

+ 2 - 2
src/uthash.h

@@ -408,7 +408,7 @@ do {
 do {                                                                             \
   IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; )                                     \
   (add)->hh.hashv = (hashval);                                                   \
-  (add)->hh.key = (char*) (keyptr);                                              \
+  (add)->hh.key = (const void*) (keyptr);                                        \
   (add)->hh.keylen = (unsigned) (keylen_in);                                     \
   if (!(head)) {                                                                 \
     (add)->hh.next = NULL;                                                       \
@@ -1142,7 +1142,7 @@ typedef struct UT_hash_handle {
    void *next;                       /* next element in app order      */
    struct UT_hash_handle *hh_prev;   /* previous hh in bucket order    */
    struct UT_hash_handle *hh_next;   /* next hh in bucket order        */
-   void *key;                        /* ptr to enclosing struct's key  */
+   const void *key;                  /* ptr to enclosing struct's key  */
    unsigned keylen;                  /* enclosing struct's key len     */
    unsigned hashv;                   /* result of hash-fcn(key)        */
 } UT_hash_handle;