]> granicus.if.org Git - json-c/commitdiff
json_object_private: Use unsigned 32-bit integer type for refcount
authorBjörn Esser <besser82@fedoraproject.org>
Sat, 16 Dec 2017 16:09:39 +0000 (17:09 +0100)
committerBjörn Esser <besser82@fedoraproject.org>
Sun, 17 Dec 2017 11:51:17 +0000 (12:51 +0100)
json_object.c
json_object_private.h

index 7c7438d8ea21b5e823d59bd8e6221d3f04246d0c..da96f4cd5b9b1e0a7bf80f073b34982922f8290a 100644 (file)
@@ -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
index 53be70db089838bf3b0029c5e224596307ba22cf..51134b60a298203fb412d45f45d299699cfd4db8 100644 (file)
@@ -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;