Skip to content

Commit

Permalink
FIX: crash in enline
Browse files Browse the repository at this point in the history
related to: zsx#16

(cherry picked from commit 11a9478)
  • Loading branch information
Oldes committed Jun 2, 2020
1 parent 9cf326b commit 70c51ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/s-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,11 @@ static REBYTE seed_str[SEED_LEN] = {
// Add missing CRs:
while (cnt > 0) {
bp[tail--] = bp[len]; // Copy src to dst.
if (bp[len--] == LF && bp[len] != CR) {
if (bp[len] == LF && (len == 0 || bp[len - 1] != CR)) {
bp[tail--] = CR;
cnt--;
}
len--;
}
}

Expand Down Expand Up @@ -495,10 +496,11 @@ static REBYTE seed_str[SEED_LEN] = {
// Add missing CRs:
while (cnt > 0) {
bp[tail--] = bp[len]; // Copy src to dst.
if (bp[len--] == LF && bp[len] != CR) {
if (bp[len] == LF && (len == 0 || bp[len - 1] != CR)) {
bp[tail--] = CR;
cnt--;
}
len--;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/tests/units/crash-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Rebol [
;@@ https://github.com/Oldes/Rebol-issues/issues/1514
--assert error? try [try/except [1 / 0] :add] ;- no crash

--test-- {enline "^/"}
--assert string? enline "^/" ;- no crash
--assert string? enline "^/č" ;- no crash (unicode version)

===end-group===

~~~end-file~~~

0 comments on commit 70c51ba

Please sign in to comment.