This is an archive of the discontinued LLVM Phabricator instance.

[lld] Use %u instead of %d for uint32_t formatting
AcceptedPublic

Authored by hughbe on Jan 22 2017, 11:36 AM.

Details

Reviewers
ruiu
llvm-commits
Summary

StringTableOff is a uint32_t. However, here, we print it as a signed decimal (%d), which is wrong.

Diff Detail

Event Timeline

hughbe created this revision.Jan 22 2017, 11:36 AM
hughbe updated this revision to Diff 85290.Jan 22 2017, 11:41 AM
hughbe updated this revision to Diff 85292.Jan 22 2017, 11:43 AM
hughbe updated this revision to Diff 85295.Jan 22 2017, 11:45 AM
joerg added a subscriber: joerg.Jan 22 2017, 12:59 PM

Neither is correct. It should be casted either to uintmax_t and printed with %ju or PRIu32 be used. The fancy new formatting system might also work of course, but won't give you a C string.
That said, this should also be changed to use snprintf...

ruiu added a subscriber: ruiu.Jan 23 2017, 10:10 AM

I'd probably just cast to unsigned long and use lu. Using sprintf with (size_t)COFF::NameSize is indeed better.

hughbe updated this revision to Diff 88155.Feb 12 2017, 8:59 PM
ruiu accepted this revision.Feb 12 2017, 9:02 PM

LGTM

This revision is now accepted and ready to land.Feb 12 2017, 9:02 PM
hughbe updated this revision to Diff 88157.Feb 12 2017, 10:35 PM

Use snprintf

I assume you made a typo in your comment @ruiu, and meant snprintf

Sorry for updating after you approved, I didn't notice!

ruiu added a comment.Feb 13 2017, 9:04 AM

Still LGTM. Please run the tests and submit.