Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a66a6cc

Browse files
committedNov 11, 2021
Fix for clang ub sanitizer
1 parent 21f767f commit a66a6cc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
 

‎json_object.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,7 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
10581058
format_drops_decimals = 1;
10591059

10601060
looks_numeric = /* Looks like *some* kind of number */
1061-
is_plain_digit(buf[0]) ||
1062-
(size > 1 && buf[0] == '-' && is_plain_digit(buf[1]));
1061+
is_plain_digit(buf[0]) || (size > 1 && buf[0] == '-' && is_plain_digit(buf[1]));
10631062

10641063
if (size < (int)sizeof(buf) - 2 && looks_numeric && !p && /* Has no decimal point */
10651064
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
12831282
return NULL;
12841283
jso->len = len;
12851284
memcpy(jso->c_string.idata, s, len);
1286-
jso->c_string.idata[len] = '\0';
1285+
// Cast below needed for Clang UB sanitizer
1286+
((char *)jso->c_string.idata)[len] = '\0';
12871287
return &jso->base;
12881288
}
12891289

@@ -1733,8 +1733,8 @@ static int json_object_deep_copy_recursive(struct json_object *src, struct json_
17331733
/* This handles the `json_type_null` case */
17341734
if (!iter.val)
17351735
jso = NULL;
1736-
else if (json_object_deep_copy_recursive(iter.val, src, iter.key, UINT_MAX, &jso,
1737-
shallow_copy) < 0)
1736+
else if (json_object_deep_copy_recursive(iter.val, src, iter.key, UINT_MAX,
1737+
&jso, shallow_copy) < 0)
17381738
{
17391739
json_object_put(jso);
17401740
return -1;

‎linkhash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static unsigned long lh_char_hash(const void *k)
486486
#endif
487487
}
488488

489-
return hashlittle((const char *)k, strlen((const char *)k), random_seed);
489+
return hashlittle((const char *)k, strlen((const char *)k), (uint32_t)random_seed);
490490
}
491491

492492
int lh_char_equal(const void *k1, const void *k2)

0 commit comments

Comments
 (0)
Please sign in to comment.