Fix reference counting on true, false and null
Initialize their reference counts to (unsigned int)-1 to disable reference counting on them. It already was meant to work like this, but the reference counts were just initialized to 1 instead of -1. Thanks to Andrew Thompson for reporting this issue.
This commit is contained in:
parent
a2a9107600
commit
f284e3c069
@ -784,7 +784,7 @@ json_t *json_true(void)
|
||||
{
|
||||
static json_t the_true = {
|
||||
.type = JSON_TRUE,
|
||||
.refcount = (unsigned int)1
|
||||
.refcount = (unsigned int)-1
|
||||
};
|
||||
return &the_true;
|
||||
}
|
||||
@ -794,7 +794,7 @@ json_t *json_false(void)
|
||||
{
|
||||
static json_t the_false = {
|
||||
.type = JSON_FALSE,
|
||||
.refcount = (unsigned int)1
|
||||
.refcount = (unsigned int)-1
|
||||
};
|
||||
return &the_false;
|
||||
}
|
||||
@ -804,7 +804,7 @@ json_t *json_null(void)
|
||||
{
|
||||
static json_t the_null = {
|
||||
.type = JSON_NULL,
|
||||
.refcount = (unsigned int)1
|
||||
.refcount = (unsigned int)-1
|
||||
};
|
||||
return &the_null;
|
||||
}
|
||||
|
@ -150,5 +150,36 @@ int main()
|
||||
fail("json_null failed");
|
||||
json_decref(value);
|
||||
|
||||
/* Test reference counting on singletons (true, false, null) */
|
||||
value = json_true();
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting true works incorrectly");
|
||||
json_decref(value);
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting true works incorrectly");
|
||||
json_incref(value);
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting true works incorrectly");
|
||||
|
||||
value = json_false();
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting false works incorrectly");
|
||||
json_decref(value);
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting false works incorrectly");
|
||||
json_incref(value);
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting false works incorrectly");
|
||||
|
||||
value = json_null();
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting null works incorrectly");
|
||||
json_decref(value);
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting null works incorrectly");
|
||||
json_incref(value);
|
||||
if(value->refcount != (unsigned int)-1)
|
||||
fail("refcounting null works incorrectly");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user