Skip to content

Commit 70c51ba

Browse files
committed
FIX: crash in enline
related to: zsx#16 (cherry picked from commit 11a9478)
1 parent 9cf326b commit 70c51ba

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/core/s-ops.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,11 @@ static REBYTE seed_str[SEED_LEN] = {
458458
// Add missing CRs:
459459
while (cnt > 0) {
460460
bp[tail--] = bp[len]; // Copy src to dst.
461-
if (bp[len--] == LF && bp[len] != CR) {
461+
if (bp[len] == LF && (len == 0 || bp[len - 1] != CR)) {
462462
bp[tail--] = CR;
463463
cnt--;
464464
}
465+
len--;
465466
}
466467
}
467468

@@ -495,10 +496,11 @@ static REBYTE seed_str[SEED_LEN] = {
495496
// Add missing CRs:
496497
while (cnt > 0) {
497498
bp[tail--] = bp[len]; // Copy src to dst.
498-
if (bp[len--] == LF && bp[len] != CR) {
499+
if (bp[len] == LF && (len == 0 || bp[len - 1] != CR)) {
499500
bp[tail--] = CR;
500501
cnt--;
501502
}
503+
len--;
502504
}
503505
}
504506

src/tests/units/crash-test.r3

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ Rebol [
125125
;@@ https://github.com/Oldes/Rebol-issues/issues/1514
126126
--assert error? try [try/except [1 / 0] :add] ;- no crash
127127

128+
--test-- {enline "^/"}
129+
--assert string? enline "^/" ;- no crash
130+
--assert string? enline "^/č" ;- no crash (unicode version)
131+
128132
===end-group===
129133

130134
~~~end-file~~~

0 commit comments

Comments
 (0)