echo
: fix wrapping behavior of octal sequences
#5218
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Funny behaviour in GNU:
Even though the octal code for
A
is\0101
. The reason that happens is because 3 octal digits is equivalent to a 9 bit integer.This is possibly a bug in GNU that nobody has fixed in 31 years or they just chose to ignore it since it is fairly minor. I was investigating this with @jdonszelmann and we found that GNU and the built-in
echo
for zsh and fish both also have this wrapping behaviour. Though it's not really a problem because it is all done usingunsigned
integers. In this PR, I've made sure to use thewrapping_*
methods for arithmetic to further avoid any problems.Some other utilities might need to be checked too. For instance
printf
:I noticed this while I was refactoring
print_escaped
, which is why that function is changed too.