Revision 3d5b3ec6 qobject/json-parser.c
b/qobject/json-parser.c | ||
---|---|---|
640 | 640 |
case JSON_STRING: |
641 | 641 |
obj = QOBJECT(qstring_from_escaped_str(ctxt, token)); |
642 | 642 |
break; |
643 |
case JSON_INTEGER: |
|
644 |
obj = QOBJECT(qint_from_int(strtoll(token_get_value(token), NULL, 10))); |
|
645 |
break; |
|
643 |
case JSON_INTEGER: { |
|
644 |
/* A possibility exists that this is a whole-valued float where the |
|
645 |
* fractional part was left out due to being 0 (.0). It's not a big |
|
646 |
* deal to treat these as ints in the parser, so long as users of the |
|
647 |
* resulting QObject know to expect a QInt in place of a QFloat in |
|
648 |
* cases like these. |
|
649 |
* |
|
650 |
* However, in some cases these values will overflow/underflow a |
|
651 |
* QInt/int64 container, thus we should assume these are to be handled |
|
652 |
* as QFloats/doubles rather than silently changing their values. |
|
653 |
* |
|
654 |
* strtoll() indicates these instances by setting errno to ERANGE |
|
655 |
*/ |
|
656 |
int64_t value; |
|
657 |
|
|
658 |
errno = 0; /* strtoll doesn't set errno on success */ |
|
659 |
value = strtoll(token_get_value(token), NULL, 10); |
|
660 |
if (errno != ERANGE) { |
|
661 |
obj = QOBJECT(qint_from_int(value)); |
|
662 |
break; |
|
663 |
} |
|
664 |
/* fall through to JSON_FLOAT */ |
|
665 |
} |
|
646 | 666 |
case JSON_FLOAT: |
647 | 667 |
/* FIXME dependent on locale */ |
648 | 668 |
obj = QOBJECT(qfloat_from_double(strtod(token_get_value(token), NULL))); |
Also available in: Unified diff