Fix GH-19088: Make sscanf %c read whitespace#22041
Conversation
Keep the %c conversion separate from %s so it reads whitespace instead of stopping at it. The %c conversion already suppresses leading whitespace skipping; it also must not treat whitespace as the end of the field.
acdb609 to
08ea8fb
Compare
|
@devnexen quick follow-up on this one: the extra |
hakre
left a comment
There was a problem hiding this comment.
can you summarize if/how %c differs now from the original code? (see file comment)
Sure. Previously Now |
Thanks for the detailed clarification – that matches exactly what I expected. The key point is that Given that this is a straightforward bug fix (and not a new feature or intentional behavioral change), it would be great to treat it as such – i.e., target the oldest supported branch where the bug exists, and remove the UPGRADING note (or replace it with a bug‑fix entry in the changelog). That way users on stable versions get the correct behavior too. I mentioned the file comment in Happy to help with any further testing or wording if needed. 😊 |
|
Ah yes, that makes sense. I added the UPGRADING note because the visible result changes, but I agree with your framing here: this is fixing the I’ll remove the UPGRADING note and keep this as a bug fix. For the target branch, I’ll follow whichever oldest supported branch the maintainers want this based on, rather than treating it as master-only. I’ll also cross-check the Tcl code before the next update so the PR text is clear about why this is a porting oversight. Thanks, this helped make the direction much clearer. |
|
That’s a great direction – thanks for taking the time to dig into the Tcl history. One small nuance: @devnexen has a point that any change in visible behavior, even a bug fix, can be a BC break for code that relied on the old (broken) Happy to help with the exact wording if needed. 😊 |
|
Yes, agreed. That is the better balance. I put the UPGRADING note back, but worded it as a correction rather than a new feature:
Pushed that in |
|
Given that this is a bug fix that isn't a security fix, |
Fixes GH-19088.
%calready disables the usual leading whitespace skip, but after that it still reused the%sscan path, which stops as soon as it sees whitespace. That madesscanf(' ', '%c%n', ...)assign an empty string and leave the offset at 0.Keep
%cseparate from%sin the scan loop so it consumes the requested number of characters, including spaces. The same scanner is used byfscanf(), so the existing%cexpectations there are updated as well.Tests run: