From 21f767f63fe4b32ca5607c5530dc6db0d23b6174 Mon Sep 17 00:00:00 2001 From: Robert Bielik Date: Wed, 10 Nov 2021 16:04:01 +0100 Subject: Add target include dirs for static library as well --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23c6eef..29a8bd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -472,6 +472,11 @@ if (BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS) ${JSON_C_SOURCES} ${JSON_C_HEADERS} ) + target_include_directories(${PROJECT_NAME}-static + PUBLIC + $ + $ + ) # rename the static library if (NOT MSVC) -- cgit v1.2.1 From a66a6cc51b62220a73fe2380bad532df3d42a23b Mon Sep 17 00:00:00 2001 From: Robert Bielik Date: Thu, 11 Nov 2021 09:35:31 +0100 Subject: Fix for clang ub sanitizer --- json_object.c | 10 +++++----- linkhash.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/json_object.c b/json_object.c index bf302e5..370e1d1 100644 --- a/json_object.c +++ b/json_object.c @@ -1058,8 +1058,7 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str format_drops_decimals = 1; looks_numeric = /* Looks like *some* kind of number */ - is_plain_digit(buf[0]) || - (size > 1 && buf[0] == '-' && is_plain_digit(buf[1])); + is_plain_digit(buf[0]) || (size > 1 && buf[0] == '-' && is_plain_digit(buf[1])); if (size < (int)sizeof(buf) - 2 && looks_numeric && !p && /* Has no decimal point */ strchr(buf, 'e') == NULL && /* Not scientific notation */ @@ -1283,7 +1282,8 @@ static struct json_object *_json_object_new_string(const char *s, const size_t l return NULL; jso->len = len; memcpy(jso->c_string.idata, s, len); - jso->c_string.idata[len] = '\0'; + // Cast below needed for Clang UB sanitizer + ((char *)jso->c_string.idata)[len] = '\0'; return &jso->base; } @@ -1733,8 +1733,8 @@ static int json_object_deep_copy_recursive(struct json_object *src, struct json_ /* This handles the `json_type_null` case */ if (!iter.val) jso = NULL; - else if (json_object_deep_copy_recursive(iter.val, src, iter.key, UINT_MAX, &jso, - shallow_copy) < 0) + else if (json_object_deep_copy_recursive(iter.val, src, iter.key, UINT_MAX, + &jso, shallow_copy) < 0) { json_object_put(jso); return -1; diff --git a/linkhash.c b/linkhash.c index ec0b995..d2f2b1b 100644 --- a/linkhash.c +++ b/linkhash.c @@ -486,7 +486,7 @@ static unsigned long lh_char_hash(const void *k) #endif } - return hashlittle((const char *)k, strlen((const char *)k), random_seed); + return hashlittle((const char *)k, strlen((const char *)k), (uint32_t)random_seed); } int lh_char_equal(const void *k1, const void *k2) -- cgit v1.2.1 From 286b4fdd2787e4e43b6912438362b4593e28f243 Mon Sep 17 00:00:00 2001 From: Robert Bielik Date: Thu, 11 Nov 2021 10:23:05 +0100 Subject: Fix uninitialized value error for clang-8 msan --- random_seed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/random_seed.c b/random_seed.c index f474e39..4622979 100644 --- a/random_seed.c +++ b/random_seed.c @@ -329,21 +329,21 @@ int json_c_get_random_seed(void) #else #ifdef HAVE_GETRANDOM { - int seed; + int seed = 0; if (get_getrandom_seed(&seed) == 0) return seed; } #endif #if defined HAVE_DEV_RANDOM && HAVE_DEV_RANDOM { - int seed; + int seed = 0; if (get_dev_random_seed(&seed) == 0) return seed; } #endif #if defined HAVE_CRYPTGENRANDOM && HAVE_CRYPTGENRANDOM { - int seed; + int seed = 0; if (get_cryptgenrandom_seed(&seed) == 0) return seed; } -- cgit v1.2.1