Eliminate use of ctype.h and replace isdigit() and tolower() with non-locale-sensitive approaches.

This commit is contained in:
Eric Haszlakiewicz
2020-08-02 04:06:44 +00:00
parent f3d8006d34
commit 8c7849e6e3
4 changed files with 16 additions and 15 deletions

View File

@@ -13,7 +13,6 @@
#include "strerror_override.h"
#include <assert.h>
#include <ctype.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
@@ -35,6 +34,9 @@
#include "snprintf_compat.h"
#include "strdup_compat.h"
/* Avoid ctype.h and locale overhead */
#define is_plain_digit(c) ((c) >= '0' && (c) <= '9')
#if SIZEOF_LONG_LONG != SIZEOF_INT64_T
#error "The long long type isn't 64-bits"
#endif
@@ -1056,8 +1058,8 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
format_drops_decimals = 1;
looks_numeric = /* Looks like *some* kind of number */
isdigit((unsigned char)buf[0]) ||
(size > 1 && buf[0] == '-' && isdigit((unsigned char)buf[1]));
is_plain_digit(buf[0]) ||
(size > 1 && buf[0] == '-' && is_plain_digit(buf[1]));
if (size < (int)sizeof(buf) - 2 && looks_numeric && !p && /* Has no decimal point */
strchr(buf, 'e') == NULL && /* Not scientific notation */