diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-05-01 16:36:32 +0930 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-05-01 16:36:32 +0930 |
commit | 2567d6cf12ad25ae6f1bf7230d83c572e72ad49f (patch) | |
tree | 552343f74210a622c0d633801ab5ccf6b6b62f99 /lua_cjson.c | |
parent | 667f354934627a885e9a627a3c2b93a673956ed8 (diff) | |
download | lua-cjson-2567d6cf12ad25ae6f1bf7230d83c572e72ad49f.tar.gz lua-cjson-2567d6cf12ad25ae6f1bf7230d83c572e72ad49f.tar.bz2 lua-cjson-2567d6cf12ad25ae6f1bf7230d83c572e72ad49f.zip |
Detect and throw error when parsing hexadecimal
Diffstat (limited to 'lua_cjson.c')
-rw-r--r-- | lua_cjson.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index cd3b9f7..de67766 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -663,19 +663,29 @@ static void json_next_number_token(json_parse_t *json, json_token_t *token) | |||
663 | { | 663 | { |
664 | const char *startptr; | 664 | const char *startptr; |
665 | char *endptr; | 665 | char *endptr; |
666 | int i; | ||
666 | 667 | ||
667 | /* FIXME: | 668 | /* JSON numbers should take the following form: |
668 | * Verify that the number takes the following form: | 669 | * -?(0|[1-9]|[1-9][0-9]+)(.[0-9]+)?([eE][-+]?[0-9]+)? |
669 | * -?(0|[1-9]|[1-9][0-9]+)(.[0-9]+)?([eE][-+]?[0-9]+)? | 670 | * |
670 | * strtod() below allows other forms (Hex, infinity, NaN,..) */ | 671 | * strtod() below allows other forms: |
671 | /* i = json->index; | 672 | * - numbers starting with '+' |
673 | * - infinity, NaN | ||
674 | * - hexidecimal numbers | ||
675 | * | ||
676 | * Infinity/NaN and numbers starting with '+' can't occur due to | ||
677 | * earlier parser error checking. | ||
678 | * | ||
679 | * Generate an error if a hexidecimal number has been | ||
680 | * provided ("0x" or "0X"). | ||
681 | */ | ||
682 | i = json->index; | ||
672 | if (json->data[i] == '-') | 683 | if (json->data[i] == '-') |
673 | i++; | 684 | i++; |
674 | j = i; | 685 | if (json->data[i] == '0' && (json->data[i + 1] | 0x20) == 'x') { |
675 | while ('0' <= json->data[i] && json->data[i] <= '9') | 686 | json_set_token_error(token, json, "invalid number (hexidecimal)"); |
676 | i++; | 687 | return; |
677 | if (i == j) | 688 | } |
678 | return T_ERROR; */ | ||
679 | 689 | ||
680 | token->type = T_NUMBER; | 690 | token->type = T_NUMBER; |
681 | startptr = &json->data[json->index]; | 691 | startptr = &json->data[json->index]; |