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

@@ -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;