echo: fix wrapping behavior of octal sequences#5218
Merged
cakebaker merged 4 commits intouutils:mainfrom Oct 3, 2023
Merged
Conversation
dc4f5a2 to
9d4f325
Compare
src/uu/echo/src/echo.rs
Outdated
| Some(n) => ret = ret.wrapping_mul(base).wrapping_add(n as u8), | ||
| None => break, | ||
| } | ||
| input.next(); |
There was a problem hiding this comment.
even though Option isn't marked #[must_use], it might be nice to do let _ = input.next()
There was a problem hiding this comment.
though maybe clippy complains because it's technically not necessary, I always like it cause it's clear we don't care (instead of the unwrap above, which I guess could be the same let _ =
Collaborator
Author
There was a problem hiding this comment.
Agreed and fixed!
9d4f325 to
4623575
Compare
Contributor
|
I'm not sure whether this is outside the scope of this PR: GNU With your solution I get: |
Collaborator
Author
|
Yeah sure, I've added it. |
|
GNU testsuite comparison: |
sylvestre
reviewed
Sep 1, 2023
sylvestre
reviewed
Sep 1, 2023
cakebaker
reviewed
Sep 25, 2023
bdc43a4 to
518e7c8
Compare
518e7c8 to
45487d4
Compare
cakebaker
reviewed
Sep 25, 2023
cakebaker
reviewed
Sep 25, 2023
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Ais\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
echofor zsh and fish both also have this wrapping behaviour. Though it's not really a problem because it is all done usingunsignedintegers. 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.