This is an archive of the discontinued LLVM Phabricator instance.

Use size_t, instead of unsigned, to represnt StringMapEntry length and alignment.
AbandonedPublic

Authored by mattd on Nov 30 2017, 3:00 PM.

Details

Summary

The original code was accessing bad data in the pathological case of
int foo[1024*1024*1024] which just happens to represent 2^32 bytes.
This was generating a bad unsigned size variable in StringMap that
was then used for memory allocation.

It turns out that StringMap's allocator was using unsigned values
when the size() operator in the class returns size_t. It seems safest,
just to use size_t when dealing with strings and their lengths.

Diff Detail

Event Timeline

mattd created this revision.Nov 30 2017, 3:00 PM
mattd added a reviewer: chandlerc.
davide requested changes to this revision.Nov 30 2017, 10:34 PM
davide added a subscriber: davide.

Matt, you should consider writing an unittest for this change.

This revision now requires changes to proceed.Nov 30 2017, 10:34 PM
mattd updated this revision to Diff 125204.Dec 1 2017, 1:11 PM
mattd edited edge metadata.
  • Added a unittest to StringMapTests.
  • Changed a use of unsigned to be size_t, when constructing a StringMapEntry.
aaron.ballman accepted this revision.Jan 2 2018, 10:04 AM
aaron.ballman added a reviewer: dblaikie.
aaron.ballman added subscribers: dblaikie, aaron.ballman.

FWIW, this LGTM, but you should wait for independent confirmation. Adding @dblaikie in case he has opinions.

dblaikie accepted this revision.Jan 4 2018, 10:22 AM

Sure, seems plausible

mattd added a comment.Jan 11 2018, 7:52 AM

Thanks @aaron.ballman @dblaikie. Is there anything else needed for commit approval?

Thanks @aaron.ballman @dblaikie. Is there anything else needed for commit approval?

Nope, you're good to commit now. Do you need someone to commit on your behalf?

mattd added a comment.Jan 11 2018, 7:59 AM

I do need someone to commit this on my behalf. Thanks!

I've committed in r322305.

Great! Thanks!

Great! Thanks!

You're welcome! If there are any issues with the commit, I'll let you know. Otherwise, you should be fine to manually close this review.

mattd abandoned this revision.Jan 12 2018, 9:32 AM

Changes have been committed at r322305.