diff options
author | David Robillard <d@drobilla.net> | 2011-01-25 01:01:48 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-25 01:01:48 +0000 |
commit | eab3301711168ac934c27c9c331a9742ac848b1c (patch) | |
tree | 35573e5cb4e9fbab8abacabbb7f547c7c4a8e843 /src | |
parent | e03b4041c0e53c041073402687d7a8a018be83d7 (diff) | |
download | serd-eab3301711168ac934c27c9c331a9742ac848b1c.tar.gz serd-eab3301711168ac934c27c9c331a9742ac848b1c.tar.bz2 serd-eab3301711168ac934c27c9c331a9742ac848b1c.zip |
Fix crash when parsing malformed numbers.
Add bad test cases (reach 95% test coverage).
git-svn-id: http://svn.drobilla.net/serd/trunk@59 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src')
-rw-r--r-- | src/reader.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/reader.c b/src/reader.c index 468e0f21..e0ffd816 100644 --- a/src/reader.c +++ b/src/reader.c @@ -809,19 +809,20 @@ except: return 0; } - -static Ref +static bool read_0_9(SerdReader reader, Ref str, bool at_least_one) { uint8_t c; if (at_least_one) { - TRY_RET(is_digit((c = peek_byte(reader)))); + if (!is_digit((c = peek_byte(reader)))) { + return error(reader, "expected digit\n"); + } push_byte(reader, str, eat_byte(reader, c)); } while (is_digit((c = peek_byte(reader)))) { push_byte(reader, str, eat_byte(reader, c)); } - return str; + return true; } // [19] exponent ::= [eE] ('-' | '+')? [0-9]+ @@ -849,21 +850,21 @@ read_number(SerdReader reader, Node* dest) has_decimal = true; // decimal case 2 (e.g. '.0' or `-.0' or `+.0') push_byte(reader, str, eat_byte(reader, c)); - TRY_THROW(str = read_0_9(reader, str, true)); + TRY_THROW(read_0_9(reader, str, true)); } else { // all other cases ::= ( '-' | '+' ) [0-9]+ ( . )? ( [0-9]+ )? ... - TRY_THROW(str = read_0_9(reader, str, true)); + TRY_THROW(read_0_9(reader, str, true)); if ((c = peek_byte(reader)) == '.') { has_decimal = true; push_byte(reader, str, eat_byte(reader, c)); - TRY_THROW(str = read_0_9(reader, str, false)); + TRY_THROW(read_0_9(reader, str, false)); } } c = peek_byte(reader); if (c == 'e' || c == 'E') { // double push_byte(reader, str, eat_byte(reader, c)); - str = read_0_9(reader, str, true); + read_0_9(reader, str, true); datatype = push_string(reader, XSD_DOUBLE, strlen(XSD_DOUBLE) + 1); } else if (has_decimal) { datatype = push_string(reader, XSD_DECIMAL, strlen(XSD_DECIMAL) + 1); |