mirror of
https://github.com/json-c/json-c.git
synced 2026-03-29 09:59:06 +08:00
Eliminate use of ctype.h and replace isdigit() and tolower() with non-locale-sensitive approaches.
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "strerror_override.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -20,6 +19,9 @@
|
||||
#include "strdup_compat.h"
|
||||
#include "vasprintf_compat.h"
|
||||
|
||||
/* Avoid ctype.h and locale overhead */
|
||||
#define is_plain_digit(c) ((c) >= '0' && (c) <= '9')
|
||||
|
||||
/**
|
||||
* JavaScript Object Notation (JSON) Pointer
|
||||
* RFC 6901 - https://tools.ietf.org/html/rfc6901
|
||||
@@ -47,7 +49,7 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx
|
||||
*/
|
||||
if (len == 1)
|
||||
{
|
||||
if (isdigit((unsigned char)path[0]))
|
||||
if (is_plain_digit(path[0]))
|
||||
{
|
||||
*idx = (path[0] - '0');
|
||||
goto check_oob;
|
||||
@@ -64,7 +66,7 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx
|
||||
/* RFC states base-10 decimals */
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (!isdigit((unsigned char)path[i]))
|
||||
if (!is_plain_digit(path[i]))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user