mirror of
https://github.com/kgabis/parson.git
synced 2025-02-04 06:42:55 +08:00
Fixed issue with MSVC and unicode characters.
Functions in MSVC's ctype.h create runtime error when passed negative char value.
This commit is contained in:
parent
457fa1100f
commit
b2dbaece40
8
parson.c
8
parson.c
@ -73,7 +73,7 @@ struct json_array_t {
|
|||||||
/* Various */
|
/* Various */
|
||||||
static int try_realloc(void **ptr, size_t new_size);
|
static int try_realloc(void **ptr, size_t new_size);
|
||||||
static char * parson_strndup(const char *string, size_t n);
|
static char * parson_strndup(const char *string, size_t n);
|
||||||
static int is_utf(const char *string);
|
static int is_utf(const unsigned char *string);
|
||||||
static int is_decimal(const char *string, size_t length);
|
static int is_decimal(const char *string, size_t length);
|
||||||
|
|
||||||
/* JSON Object */
|
/* JSON Object */
|
||||||
@ -124,7 +124,7 @@ static char * parson_strndup(const char *string, size_t n) {
|
|||||||
return output_string;
|
return output_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_utf(const char *s) {
|
static int is_utf(const unsigned char *s) {
|
||||||
return isxdigit(s[0]) && isxdigit(s[1]) && isxdigit(s[2]) && isxdigit(s[3]);
|
return isxdigit(s[0]) && isxdigit(s[1]) && isxdigit(s[2]) && isxdigit(s[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ static const char * get_processed_string(const char **string) {
|
|||||||
case 't': current_char = '\t'; break;
|
case 't': current_char = '\t'; break;
|
||||||
case 'u':
|
case 'u':
|
||||||
unprocessed_ptr++;
|
unprocessed_ptr++;
|
||||||
if (!is_utf(unprocessed_ptr) ||
|
if (!is_utf((const unsigned char*)unprocessed_ptr) ||
|
||||||
sscanf(unprocessed_ptr, "%4x", &utf_val) == EOF) {
|
sscanf(unprocessed_ptr, "%4x", &utf_val) == EOF) {
|
||||||
parson_free(output); return NULL;
|
parson_free(output); return NULL;
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ static const char * get_processed_string(const char **string) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (iscntrl(current_char)) { /* no control characters allowed */
|
} else if (iscntrl((unsigned char)current_char)) { /* no control characters allowed */
|
||||||
parson_free(output);
|
parson_free(output);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user