Skip to content

Commit

Permalink
fix underflow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed May 1, 2024
1 parent 225d641 commit 506a608
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: yyjsonr
Type: Package
Title: Fast 'JSON', 'NDJSON' and 'GeoJSON' Parser and Generator
Version: 0.1.20.9000
Version: 0.1.20.9001
Authors@R: c(
person("Mike", "Cheng", role = c("aut", "cre", 'cph'),
email = "[email protected]"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@


# yyjsonr 0.1.20.9001 2024-05-01

* Fix underflow issue when trying to verbosely report an error at position 0

# yyjsonr 0.1.20.9000 2024-04-12

* Get size of gzipped file in an endian-neutral way. Issue #39
Expand Down
8 changes: 5 additions & 3 deletions src/R-yyjson-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,11 @@ void output_verbose_error(const char *str, yyjson_read_err err) {

// Print a "^" to point to the error
size_t pos = ERR_CONTEXT;
pos = err.pos < ERR_CONTEXT ? err.pos - 1 : ERR_CONTEXT;
for (unsigned int i = 0; i < pos; i++) {
Rprintf(" ");
if (err.pos > 0) {
pos = err.pos < ERR_CONTEXT ? err.pos - 1 : ERR_CONTEXT;
for (unsigned int i = 0; i < pos; i++) {
Rprintf(" ");
}
}
Rprintf("^\n");
}
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-bug44-infinite-loop-on-bad-string.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


test_that("Invalid string input should cause error", {

testthat::capture_output({
expect_error({
read_json_str("hello")
})
})

})

0 comments on commit 506a608

Please sign in to comment.