Refactor boolean assignments from cJSON - #205
Conversation
|
Thanks for sharing this! There are two suggestions: For the fields already guarded by Please leave |
| value = cJSON_GetObjectItemCaseSensitive(jsonTimestamp, "Authoritative"); | ||
| if (cJSON_IsBool(value)) { | ||
| aTimestamp->mAuthoritative = (bool)cJSON_GetNumberValue(value); | ||
| aTimestamp->mAuthoritative = value->valueint; |
There was a problem hiding this comment.
| aTimestamp->mAuthoritative = value->valueint; | |
| aTimestamp->mAuthoritative = JSON_IsTrue(value); |
Please do the same elsewhere.
| temp = cJSON_GetObjectItem(root, "defaultRoute"); | ||
| if (temp && temp->type != cJSON_NULL) | ||
| param->default_route = (bool)cJSON_GetNumberValue(temp); | ||
| param->default_route = temp->valueint; |
There was a problem hiding this comment.
Keep it as is; otherwise, the frontend should also be fixed (defaultRoute should be a boolean rather than a number).
There was a problem hiding this comment.
I don't really understand what the problem is here.
The frontend uses 1/0 numeric values
There was a problem hiding this comment.
defaultRoute represents whether the prefix is advertised as a default route, so it should be a boolean. When we implemented the frontend, we used 0/1. Although it works, it's not a reasonable representation.
If we want to fix this, we should fix both the frontend and the backend together: change the frontend to use true/false, and change the backend to use cJSON_IsTrue(), instead of keeping 0/1 in the frontend and replacing cJSON_GetNumberValue(value) with value->valueint in the backend.
Also, for numbers, cJSON_GetNumberValue() is actually better than value->valueint.
By the way, since these changes are all part of the same fix, it's better to squash them into a single commit instead of adding a new commit for every code change.
keep default_route as number
|
@Tarik2142 |
Description
SecurityPolicy flags in the active Thread dataset cannot be set to
false. They are always forced to true, regardless of the input.
Steps to reproduce:
(CommercialCommissioning, AutonomousEnrollment, NetworkKeyProvisioning,
TobleLink, NonCcmRouters) explicitly set to false via PUT /node/dataset/active with a JSON body containing
"false" for all five fields.
The actual bool value is mapped to item->valueint (1 for true, 0 for false).
Related
Testing
Checklist
Before submitting a Pull Request, please ensure the following: