This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix printf %a padding issue
ClosedPublic

Authored by michaelrj on Aug 9 2023, 11:42 AM.

Details

Summary

The trailing zeroes were previously not counted when calculating the
padding, which caused a high-precision number to get too much padding.

Diff Detail

Event Timeline

michaelrj created this revision.Aug 9 2023, 11:42 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 9 2023, 11:42 AM
sivachandra added inline comments.Aug 9 2023, 2:24 PM
libc/test/src/stdio/sprintf_test.cpp
872

This comment talking about what was previously happening, and that it was found via fuzzing doesn't help build the context. Instead, can you describe what exact expected behavior is being tested here?

michaelrj updated this revision to Diff 548790.Aug 9 2023, 3:30 PM

rewrite comment to clarify the bug being fixed

libc/test/src/stdio/sprintf_test.cpp
872

The fuzzing thing is a header, telling you what category this is. If you look earlier in the test there's a couple different categories of test, such as precision or width, that focus on a specific feature. Saying these are found by fuzzing clarifies that these aren't from a specific category, they're just random things found to have problems.

sivachandra accepted this revision.Aug 11 2023, 1:16 PM
sivachandra added inline comments.
libc/test/src/stdio/sprintf_test.cpp
872

There is nothing wrong if you want to say that it was found by fuzzing. But, if you do say it, you should ideally provide a reference. If this patch was a fix to a user bug, you will likely put a link to the bug report to help build context for the reader. An year later, the comment "Found via fuzzing" means almost nothing without a reference.

That said, my comment was more about describing what is being tested here rather than describing what was happening previously. Once that is fixed, the note that the bug was found via fuzzing is up to you.

880

Another nit: Add a comment here saying that the output string has a single character padding to make it 58 characters long.

This revision is now accepted and ready to land.Aug 11 2023, 1:16 PM
sivachandra added inline comments.Aug 11 2023, 1:18 PM
libc/test/src/stdio/sprintf_test.cpp
872

Just read the other patch and it seems like you want to treat "found by fuzzing" as a category of tests. I would instead call them "Padding tests" or something like that in this case and view that as a category.

michaelrj updated this revision to Diff 549520.Aug 11 2023, 2:43 PM
michaelrj marked 4 inline comments as done.

adjust test comments

libc/test/src/stdio/sprintf_test.cpp
872

the category these would fall under is "combined tests" since these aren't strictly padding tests or strictly precision tests, both of which are listed above on lines 608 and 631 respectively. The combined tests category is at the end, the section these are already in. I've removed the note that these were found via fuzzing to avoid confusion.

This revision was landed with ongoing or failed builds.Aug 15 2023, 4:23 PM
This revision was automatically updated to reflect the committed changes.