You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The doc states that json_object_get_int should set errno to EINVAL.
This is not the case! Looking at the code, in case the type is string and the parsing fails it returns 0 but errno is not set.
Steps To Reproduce
Compile the following code with no particular flags or settings:
How to Proceed?
I was on my way to issue a PR to fix this (with related test), it's a really easy fix. But I noticed that there is some inconsistency within:
json_object_get_double
json_object_get_int
json_object_get_int64
json_object_get_uint64
int and double both state that invalid conversions should set errno = EINVAL, double actually seems to do this! int64 and uint64 do not state the same and simply (at first glance) returns 0 in case of invalid parsing.
So, before going on an pushing a PR. Which way should I go? Which is the indended behaviour?
Could I go on and fix the missing errno = EINVAL or just remove the errno setting statement from the doc?
The text was updated successfully, but these errors were encountered:
The fix for this belongs in the json_parse_int64() function. That calls strtoll() with the expectation that it will set errno on failure, but the man page states that this is optional ("...may also set..."):
The implementation may also set errno to EINVAL in case no conversion was performed (no digits seen, and 0 returned).
so we'll need to set it explicitly to get consistent behavior.
Note that the errno: 0 result for the cases that start with an actual "0" are the intended behavior. In those, when the string is "coerced to a int" (as per the docs) the answer is 0 and the extra characters are supposed to be ignored.
Describe the bug
The doc states that
json_object_get_int
should seterrno
toEINVAL
.This is not the case! Looking at the code, in case the type is
string
and the parsing fails it returns0
buterrno
is not set.Steps To Reproduce
Compile the following code with no particular flags or settings:
Will give you that output:
Version and Platform
How to Proceed?
I was on my way to issue a PR to fix this (with related test), it's a really easy fix. But I noticed that there is some inconsistency within:
json_object_get_double
json_object_get_int
json_object_get_int64
json_object_get_uint64
int
anddouble
both state that invalid conversions should seterrno = EINVAL
,double
actually seems to do this!int64
anduint64
do not state the same and simply (at first glance) returns 0 in case of invalid parsing.So, before going on an pushing a PR. Which way should I go? Which is the indended behaviour?
Could I go on and fix the missing
errno = EINVAL
or just remove the errno setting statement from the doc?The text was updated successfully, but these errors were encountered: