Skip to content

Commit

Permalink
FIX: in rare cases scanner was making *null holes* in strings, when t…
Browse files Browse the repository at this point in the history
…he internal buffer was extended.

The original R3-alpha version was not affected, but there was a AddressSanitizer error report, which Atronix fixed in this commit: zsx@3d7484c

Atronix fixed this issue later in this commit: zsx@2e56b0c

Which I have not noticed.

In my commit I included this fix also in Scan_Item function.
  • Loading branch information
Oldes committed Jun 28, 2019
1 parent 0c166c6 commit 97334b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/l-scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@

src++;

*UNI_SKIP(buf, buf->tail) = chr;

if (SERIES_LEN(buf) >= SERIES_REST(buf)) Extend_Series(buf, 1);
if (SERIES_FULL(buf))
Extend_Series(buf, 1);

buf->tail ++;
*UNI_SKIP(buf, buf->tail) = chr;
buf->tail++;
}

src++; // Skip ending quote or brace.
Expand Down Expand Up @@ -532,9 +532,11 @@

src++;

*UNI_SKIP(buf, buf->tail) = c; // not affected by Extend_Series
if (SERIES_FULL(buf))
Extend_Series(buf, 1);

if (++(buf->tail) >= SERIES_REST(buf)) Extend_Series(buf, 1);
*UNI_SKIP(buf, buf->tail) = c;
buf->tail++;
}

if (*src && *src == term) src++;
Expand Down
27 changes: 27 additions & 0 deletions src/tests/units/lexer-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,31 @@ Rebol [

===end-group===


===start-group=== "Special tests"

--test-- "NULLs inside loaded string"
;@@ https://github.com/Oldes/Rebol3/commit/6f59240d7d4379a50fec29c4e74290ad61ba73ba
out: ""
--assert not error? try [
;- using CALL as it could be reproduced only when the internal buffer is being extended durring load
data: make string! 40000
insert/dup data "ABCD" 10000

dir: join system/options/path %r3/src/tests/units/files/

save dir/tmp.data reduce [1 data]
exe: rejoin [system/options/home last split-path system/options/boot]

;@@ CALL seems not to work same on all OSes :-(
either system/version/4 = 3 [
call/wait/output probe rejoin [to-local-file exe { -s } to-local-file dir/bug-load-null.r3] out
][ call/wait/output probe reduce [exe dir/bug-load-null.r3] out ]

probe out
]
--assert out = "Test OK"
error? try [ delete dir/tmp.data ]

===end-group===
~~~end-file~~~

0 comments on commit 97334b0

Please sign in to comment.