From: Eric Haszlakiewicz Date: Wed, 27 Feb 2013 03:09:10 +0000 (-0600) Subject: Merge branch 'remicollet-issue-float' X-Git-Tag: json-c-0.11-20130402~14 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=5b36a432c8b13f3534ade4c4b5ac721b6e35287a;p=thirdparty%2Fjson-c.git Merge branch 'remicollet-issue-float' Conflicts: json_util.c --- 5b36a432c8b13f3534ade4c4b5ac721b6e35287a diff --cc json_util.c index 194f290f,0a598115..111fa01a --- a/json_util.c +++ b/json_util.c @@@ -146,31 -142,11 +146,36 @@@ int json_object_to_file(char *filename return json_object_to_file_ext(filename, obj, JSON_C_TO_STRING_PLAIN); } + int json_parse_double(const char *buf, double *retval) + { + return (sscanf(buf, "%lf", retval)==1 ? 0 : 1); + } + +/* + * Not all implementations of sscanf actually work properly. + * Check whether the one we're currently using does, and if + * it's broken, enable the workaround code. + */ +static void sscanf_is_broken_test() +{ + int64_t num64; + + (void)sscanf(" -01234567890123456789012345", "%" SCNd64, &num64); + int ret_errno = errno; + int is_int64_min = (num64 == INT64_MIN); + + (void)sscanf(" 01234567890123456789012345", "%" SCNd64, &num64); + int ret_errno2 = errno; + int is_int64_max = (num64 == INT64_MAX); + + if (ret_errno != ERANGE || !is_int64_min || + ret_errno2 != ERANGE || !is_int64_max) + { + MC_DEBUG("sscanf_is_broken_test failed, enabling workaround code\n"); + sscanf_is_broken = 1; + } +} + int json_parse_int64(const char *buf, int64_t *retval) { int64_t num64;