From: Anders F Björklund Date: Sun, 16 Sep 2018 16:48:03 +0000 (+0200) Subject: Proper use of const qualifier char* strings X-Git-Tag: v3.5~26^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=063c3718d8ccb6b4007ec46329b425db30a40b39;p=thirdparty%2Fccache.git Proper use of const qualifier char* strings --- diff --git a/src/hash.c b/src/hash.c index 3b462ca9e..fec5f7065 100644 --- a/src/hash.c +++ b/src/hash.c @@ -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. diff --git a/src/unify.c b/src/unify.c index 53c3a0faa..dacf69cd9 100644 --- a/src/unify.c +++ b/src/unify.c @@ -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++) { diff --git a/unittest/framework.c b/unittest/framework.c index 404367a9a..f98a6c694 100644 --- a/unittest/framework.c +++ b/unittest/framework.c @@ -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; } diff --git a/unittest/framework.h b/unittest/framework.h index 940b2fec7..29ff43f1e 100644 --- a/unittest/framework.h +++ b/unittest/framework.h @@ -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); diff --git a/unittest/test_conf.c b/unittest/test_conf.c index 9271a88cc..bb3f95ce5 100644 --- a/unittest/test_conf.c +++ b/unittest/test_conf.c @@ -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); } }