From 596c9d2d0387d962e6579e0773daf823410e32bd Mon Sep 17 00:00:00 2001 From: hanjinpeng Date: Wed, 9 Sep 2026 22:02:31 -0400 Subject: [PATCH] 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. --- arraylist.c | 5 ++++- json_tokener.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arraylist.c b/arraylist.c index 88c6d23..f1b73b0 100644 --- a/arraylist.c +++ b/arraylist.c @@ -83,7 +83,10 @@ static int array_list_expand_internal(struct array_list *arr, size_t max) void *t; 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; /* Avoid undefined behaviour on size_t overflow */ if (arr->size >= SIZE_T_MAX / 2) diff --git a/json_tokener.c b/json_tokener.c index cfa01ab..516142a 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -1157,7 +1157,7 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char * } if (numuint64 <= INT64_MAX) { - num64 = (uint64_t)numuint64; + num64 = (int64_t)numuint64; current = json_object_new_int64(num64); if (current == NULL) {