Skip to content

Commit 1d2932d

Browse files
authored
Merge pull request #109 from maciejhirsz/bugfixes
Fixes #106
2 parents 857fa9f + 8efe81b commit 1d2932d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "json"
3-
version = "0.11.5"
3+
version = "0.11.6"
44
authors = ["Maciej Hirsz <maciej.hirsz@gmail.com>"]
55
description = "JSON implementation in Rust"
66
repository = "https://github.com/maciejhirsz/json-rust"

src/parser.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ macro_rules! allow_number_extensions {
281281
// quite handy as the only number that can begin with zero, has to have
282282
// a zero mantissa. Leading zeroes are illegal in JSON!
283283
($parser:ident) => ({
284-
let mut num = 0;
285-
let mut e = 0;
286-
let ch = $parser.read_byte();
287-
allow_number_extensions!($parser, num, e, ch)
284+
if $parser.is_eof() {
285+
0.into()
286+
} else {
287+
let mut num = 0;
288+
let mut e = 0;
289+
let ch = $parser.read_byte();
290+
allow_number_extensions!($parser, num, e, ch)
291+
}
288292
})
289293
}
290294

@@ -383,6 +387,8 @@ impl<'a> Parser<'a> {
383387
// is virtually irrelevant.
384388
#[inline(always)]
385389
fn read_byte(&mut self) -> u8 {
390+
debug_assert!(self.index < self.length, "Reading out of bounds");
391+
386392
unsafe { *self.byte_ptr.offset(self.index as isize) }
387393
}
388394

tests/parse.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,9 @@ fn does_not_panic_on_single_unicode_char() {
327327
assert!(parse(&string).is_err());
328328
}
329329

330+
#[test]
331+
fn does_not_panic_on_single_zero() {
332+
let source = "0";
333+
334+
parse(source).unwrap();
335+
}

0 commit comments

Comments
 (0)