Menu

#39 cJSON_CreateBool bug

v1.0 (example)
closed-rejected
nobody
None
5
2014-05-31
2014-05-06
No

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.

Discussion

  • Jerome Lang

    Jerome Lang - 2014-05-06

    It should work like intended without parenthesis since the assignment operator has a lower priority than ?:

     
  • Marcos Kirsch

    Marcos Kirsch - 2014-05-06

    You are right, I just verified that too. Looks like my code has a bug elsewhere. Thanks!

     
  • Dave Gamble

    Dave Gamble - 2014-05-31
    • status: unread --> closed-rejected
     

Log in to post a comment.