cJSON_CreateBool bug
Brought to you by:
davegamble
Unless I understand correctly, the intended behavior is that if the client passes 0, a false is created, else a true.
This is the implementation provided (reformatted for readability):
cJSON cJSON_CreateBool(int b)
{
cJSON item=cJSON_New_Item();
if(item)item->type=b?cJSON_True:cJSON_False;
return item;
}
This is the implementation it should have:
cJSON cJSON_CreateBool(int b)
{
cJSON item=cJSON_New_Item();
if(item)item->type=(b?cJSON_True:cJSON_False);
return item;
}
... it's missing the parenthesis, so it assigns b to item->type.
It should work like intended without parenthesis since the assignment operator has a lower priority than ?:
You are right, I just verified that too. Looks like my code has a bug elsewhere. Thanks!