Skip to content

Commit 97334b0

Browse files
committed
FIX: in rare cases scanner was making *null holes* in strings, when the 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.
1 parent 0c166c6 commit 97334b0

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/core/l-scan.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@
457457

458458
src++;
459459

460-
*UNI_SKIP(buf, buf->tail) = chr;
461-
462-
if (SERIES_LEN(buf) >= SERIES_REST(buf)) Extend_Series(buf, 1);
460+
if (SERIES_FULL(buf))
461+
Extend_Series(buf, 1);
463462

464-
buf->tail ++;
463+
*UNI_SKIP(buf, buf->tail) = chr;
464+
buf->tail++;
465465
}
466466

467467
src++; // Skip ending quote or brace.
@@ -532,9 +532,11 @@
532532

533533
src++;
534534

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

537-
if (++(buf->tail) >= SERIES_REST(buf)) Extend_Series(buf, 1);
538+
*UNI_SKIP(buf, buf->tail) = c;
539+
buf->tail++;
538540
}
539541

540542
if (*src && *src == term) src++;

src/tests/units/lexer-test.r3

+27
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,31 @@ Rebol [
2626

2727
===end-group===
2828

29+
30+
===start-group=== "Special tests"
31+
32+
--test-- "NULLs inside loaded string"
33+
;@@ https://github.com/Oldes/Rebol3/commit/6f59240d7d4379a50fec29c4e74290ad61ba73ba
34+
out: ""
35+
--assert not error? try [
36+
;- using CALL as it could be reproduced only when the internal buffer is being extended durring load
37+
data: make string! 40000
38+
insert/dup data "ABCD" 10000
39+
40+
dir: join system/options/path %r3/src/tests/units/files/
41+
42+
save dir/tmp.data reduce [1 data]
43+
exe: rejoin [system/options/home last split-path system/options/boot]
44+
45+
;@@ CALL seems not to work same on all OSes :-(
46+
either system/version/4 = 3 [
47+
call/wait/output probe rejoin [to-local-file exe { -s } to-local-file dir/bug-load-null.r3] out
48+
][ call/wait/output probe reduce [exe dir/bug-load-null.r3] out ]
49+
50+
probe out
51+
]
52+
--assert out = "Test OK"
53+
error? try [ delete dir/tmp.data ]
54+
55+
===end-group===
2956
~~~end-file~~~

0 commit comments

Comments
 (0)