fix(echo): handle overflow in octal/hex escape parsing

Use wrapping arithmetic when parsing octal and hex escapes in echo to
prevent panics on overflow and ensure consistent behavior with other
shells. This change allows echo to process escape sequences like \5555
without crashing, keeping the same behavior as 3.7.1.

```
$ ./fish --version
fish, version 3.7.1
$ ./fish -c 'echo -e "\5555"'
m5
```
This commit is contained in:
Dezhi Wu
2025-06-28 10:17:14 +08:00
parent 3e098249a5
commit 144725e947
2 changed files with 7 additions and 2 deletions

View File

@@ -143,6 +143,11 @@ echo -e 'abc\121def'
echo -e 'abc\1212def'
#CHECK: abcQdef
#CHECK: abcQ2def
# Test octal overflow: \5555 = 555 octal = 365 decimal, wraps to 109 decimal (155 octal)
# Followed by literal '5' character (065 octal)
echo -ne '\5555' | display_bytes
#CHECK: 0000000 155 065
#CHECK: 0000002
echo -e 'abc\cdef' # won't output a newline!
#CHECK: abc
echo ''