]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Proper use of const qualifier char* strings
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 16 Sep 2018 16:48:03 +0000 (18:48 +0200)
committerAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 16 Sep 2018 16:48:26 +0000 (18:48 +0200)
src/hash.c
src/unify.c
unittest/framework.c
unittest/framework.h
unittest/test_conf.c

index 3b462ca9eaf7ad22c0af43a8dd577691a945e481..fec5f706577322eec58bb79a40085aecc3744f73 100644 (file)
@@ -28,7 +28,7 @@ hash_start(struct mdfour *md)
 void
 hash_buffer(struct mdfour *md, const void *s, size_t len)
 {
-       mdfour_update(md, (unsigned char *)s, len);
+       mdfour_update(md, (const unsigned char *)s, len);
 }
 
 // Return the hash result as a hex string. Caller frees.
index 53c3a0faaccc5997262cc9cba89de956598825c9..dacf69cd9c077b882dcce0079e508ef0b2e6e40f 100644 (file)
@@ -218,8 +218,8 @@ unify(struct mdfour *hash, unsigned char *p, size_t size)
                        unsigned char q = p[ofs];
                        int i;
                        for (i = 0; i < tokens[q].num_toks; i++) {
-                               unsigned char *s = (unsigned char *)tokens[q].toks[i];
-                               int len = strlen((char *)s);
+                               const unsigned char *s = (const unsigned char *)tokens[q].toks[i];
+                               int len = strlen((const char *)s);
                                if (size >= ofs+len && memcmp(&p[ofs], s, len) == 0) {
                                        int j;
                                        for (j = 0; s[j]; j++) {
index 404367a9a74f9542cb4500700461e8404cafcdae..f98a6c694b120c567d0b853d307a81e032d5aac3 100644 (file)
@@ -211,8 +211,8 @@ cct_check_int_eq(const char *file, int line, const char *expression,
 
 bool
 cct_check_str_eq(const char *file, int line, const char *expression,
-                 const char *expected, const char *actual, bool free1,
-                 bool free2)
+                 char *expected, char *actual,
+                bool free1, bool free2)
 {
        bool result;
 
@@ -229,10 +229,10 @@ cct_check_str_eq(const char *file, int line, const char *expression,
        }
 
        if (free1) {
-               free((char *)expected);
+               free(expected);
        }
        if (free2) {
-               free((char *)actual);
+               free(actual);
        }
        return result;
 }
index 940b2fec787c9bd51e5272364306f5301a4be5b4..29ff43f1ef200c2aff05fbc068af9e9e0329de93 100644 (file)
@@ -140,8 +140,8 @@ bool cct_check_float_eq(const char *file, int line, const char *expression,
 bool cct_check_int_eq(const char *file, int line, const char *expression,
                       int64_t expected, int64_t actual);
 bool cct_check_str_eq(const char *file, int line, const char *expression,
-                      const char *expected, const char *actual, bool free1,
-                      bool free2);
+                      char *expected, char *actual,
+                     bool free1, bool free2);
 bool cct_check_args_eq(const char *file, int line, const char *expression,
                        struct args *expected, struct args *actual,
                        bool free1, bool free2);
index 9271a88cc32086eedb1120a5286ab601d63a15e3..bb3f95ce502b86f9a9c5361c77abf011937063aa 100644 (file)
@@ -21,7 +21,7 @@
 #define N_CONFIG_ITEMS 32
 static struct {
        char *descr;
-       const char *origin;
+       char *origin;
 } received_conf_items[N_CONFIG_ITEMS];
 static size_t n_received_conf_items = 0;
 
@@ -30,7 +30,7 @@ conf_item_receiver(const char *descr, const char *origin, void *context)
 {
        (void)context;
        received_conf_items[n_received_conf_items].descr = x_strdup(descr);
-       received_conf_items[n_received_conf_items].origin = origin;
+       received_conf_items[n_received_conf_items].origin = x_strdup(origin);
        ++n_received_conf_items;
 }
 
@@ -40,6 +40,7 @@ free_received_conf_items(void)
        while (n_received_conf_items > 0) {
                --n_received_conf_items;
                free(received_conf_items[n_received_conf_items].descr);
+               free(received_conf_items[n_received_conf_items].origin);
        }
 }