Page MenuHomePhabricator

[DSE][NFC] Need to be carefull mixing signed and unsigned types

Authored by ebrevnov on Dec 4 2020, 3:09 AM.



Currently in some places we use signed type to represent size of an access and put explicit casts from unsigned to signed.
For example: int64_t EarlierSize = int64_t(Loc.Size.getValue());

Even though it doesn't loos bits (immidiatly) it may overflow and we end up with negative size. Potentially that cause later code to work incorrectly. A simple expample is a check that size is not negative.

I think it would be safer and clearer if we use unsigned type for the size and handle it appropriately.

Diff Detail

Event Timeline

ebrevnov created this revision.Dec 4 2020, 3:09 AM
ebrevnov requested review of this revision.Dec 4 2020, 3:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 3:09 AM
ebrevnov updated this revision to Diff 309505.Dec 4 2020, 3:20 AM

Updated comments

fhahn accepted this revision.Dec 7 2020, 2:00 PM

LGTM, using an unsigned type for the sizes seems a good improvement to me.


might be worth adding an assertion here to ensure that LaterSize will be positive, but it might be too cautious.

This revision is now accepted and ready to land.Dec 7 2020, 2:00 PM
ebrevnov marked an inline comment as done.Dec 8 2020, 2:15 AM