Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxxrtl: use octal encoding of non-printables. #4567

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kivikakk
Copy link
Contributor

@kivikakk kivikakk commented Aug 27, 2024

"\x0a" is a perfectly valid escape sequence, but unfortunately "\x0ac" is equivalent to "\xac", and not "\x0a" "c" as we might expect --- any number of hexadecimal characters after the \x is accepted. This can be hit pretty easily if a newline is present in a format string.

"\x{...}" syntax is only available as of C++23, so use octal format instead; a maximum of 3 digits following the backslash is accepted.

The alternative would be to render every escape like " "\x0a" ", but it seems more effort that way.

cc @whitequark.

"\x0a" is a perfectly valid escape sequence, but unfortunately "\x0ac"
is equivalent to "\xac", and not "\x0a" "c" as we might expect --- *any*
number of hexadecimal characters after the "\x" is accepted. This can be
hit pretty easily if a newline is present in a format string.

"\x{...}" syntax is only available as of C++23, so use octal format
instead; a maximum of 3 digits following the backslash is accepted.

The alternative would be to render every escape like `" "\x0a" "`, but
it seems more effort that way.
@whitequark
Copy link
Member

Oh oops, I could swear I've fixed this--I remember making a poll recently where basically nobody got it right. (Including me, evidently. I have no idea what that was about then...)

Thanks for fixing this!

@whitequark
Copy link
Member

whitequark commented Aug 27, 2024

Oh, I see, you're applying the change in commit 43ddd89 to kernel/fmt.h and not to the CXXRTL core runtime. It's a shame that we have this code duplication that got me confused, but I guess it's not easily avoidable.

@kivikakk
Copy link
Contributor Author

Oh! Yeah, I didn't even see that either; amusing that we ended up writing almost exactly the same thing — but that one looks subtly wrong? The low and middle parts only have two significant bits each (& 0x3), but they should have three (& 0x7). I might add a fix for that to this PR?

@whitequark
Copy link
Member

but that one looks subtly wrong?

Oh. <.<

The low and middle parts only have two significant bits each (& 0x3), but they should have three (& 0x7). I might add a fix for that to this PR?

Please do. <.<

(What an embarrassing mistake...)

@kivikakk
Copy link
Contributor Author

Hehehe, nah, very easy to do. (Just thinking about "3 bits" and I nearly wrote the exact same.) I did a bunch of manual tests just to make sure I wasn't making a subtly incorrect thing even subtly-er worse; for a bit I was outputting absolute garbage due to signed integer behaviour <_>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants