json_tokener, arraylist: assorted cleanups

json_tokener.c assigned to an int64_t through a (uint64_t) cast.  The
guarded range makes it harmless, but the cast names the wrong type.

array_list_expand_internal() reallocated when max == arr->size even though
the array can already hold max entries at that point, since callers only
index up to max - 1.  Skip the realloc.
This commit is contained in:
hanjinpeng committed 2026-09-13 23:08:18 -04:00
1 parent 8381d33d78
commit 596c9d2d03
2 files changed
+5 -2

No files matched your search

+4 -1
View File
@@ -83,7 +83,10 @@ static int array_list_expand_internal(struct array_list *arr, size_t max)
void *t; void *t;
size_t new_size; size_t new_size;
if (max < arr->size) /* The array can already hold max entries when max == arr->size, since
* the caller only ever indexes up to max - 1.
*/
if (max <= arr->size)
return 0; return 0;
/* Avoid undefined behaviour on size_t overflow */ /* Avoid undefined behaviour on size_t overflow */
if (arr->size >= SIZE_T_MAX / 2) if (arr->size >= SIZE_T_MAX / 2)
+1 -1
View File
@@ -1157,7 +1157,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
} }
if (numuint64 <= INT64_MAX) if (numuint64 <= INT64_MAX)
{ {
num64 = (uint64_t)numuint64; num64 = (int64_t)numuint64;
current = json_object_new_int64(num64); current = json_object_new_int64(num64);
if (current == NULL) if (current == NULL)
{ {