From c233f5c05e92909a764973524a03471bfad78f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Sat, 16 Dec 2017 17:09:39 +0100 Subject: json_object_private: Use unsigned 32-bit integer type for refcount --- json_object.c | 3 +++ json_object_private.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/json_object.c b/json_object.c index 7c7438d..da96f4c 100644 --- a/json_object.c +++ b/json_object.c @@ -169,6 +169,9 @@ extern struct json_object* json_object_get(struct json_object *jso) { if (!jso) return jso; + // Don't overflow the refcounter. + assert(jso->_ref_count < UINT_FAST32_MAX); + #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING) __sync_add_and_fetch(&jso->_ref_count, 1); #else diff --git a/json_object_private.h b/json_object_private.h index 53be70d..51134b6 100644 --- a/json_object_private.h +++ b/json_object_private.h @@ -29,7 +29,7 @@ struct json_object enum json_type o_type; json_object_private_delete_fn *_delete; json_object_to_json_string_fn *_to_json_string; - int _ref_count; + uint_fast32_t _ref_count; struct printbuf *_pb; union data { json_bool c_boolean; -- cgit v1.2.1