This is an archive of the discontinued LLVM Phabricator instance.

[ObjCopy] Fix type mismatch in writeCodeSignatureData()
ClosedPublic

Authored by jmroot on Jun 18 2022, 4:10 AM.

Details

Summary

The result of pointer subtraction is of type ptrdiff_t, which is not necessarily the same underlying type as ssize_t. This can lead to a compilation error since std::min requires both parameters to be the same type.

Fixes: https://github.com/llvm/llvm-project/issues/54846

Diff Detail

Event Timeline

jmroot created this revision.Jun 18 2022, 4:10 AM
Herald added a project: Restricted Project. · View Herald Transcript
jmroot requested review of this revision.Jun 18 2022, 4:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2022, 4:10 AM
jhenderson accepted this revision.Jun 20 2022, 12:42 AM

LGTM, but maybe give @alexander-shaposhnikov a chance to comment (i.e. give it a day or two to land this or until he responds).

This revision is now accepted and ready to land.Jun 20 2022, 12:42 AM

My comment about using size_t instead are not a blocker, just an opinion.

Whenever this is ready to land, if you need us to land this, please comment so and we will submit.

llvm/lib/ObjCopy/MachO/MachOWriter.cpp
522–525

I am sorry for the initial blunder and sorry for breaking this for 32 bits platforms.

I was wondering why we did this original. The StringRef constructor needs size_t for its second argument. BlockSize is already size_t. Because of the while loop check HashReadEnd - CurrHashReadPosition has to be positive. I wonder if the right thing here is casting to size_t.

(ssize_t has a weird range. It is not a "signed size_t", but a size_t that allows -1 to be returned. But in any case, there's no negative numbers being handled here, it is just a ptrdiff_t which we know to be positive).

llvm/lib/ObjCopy/MachO/MachOWriter.cpp
522–525
jmroot updated this revision to Diff 438524.Jun 20 2022, 6:46 PM

Now using size_t for the two casts, since that is what the StringRef constructor actually takes.

drodriguez accepted this revision.Jun 21 2022, 1:58 PM
jmroot marked 2 inline comments as done.Jun 21 2022, 5:26 PM

Thanks for the reviews. I don't have commit access, so could someone who does please commit at your convenience?

Thanks for the reviews. I don't have commit access, so could someone who does please commit at your convenience?

What username and email would you like for the commit message? See https://llvm.org/docs/Phabricator.html#committing-someone-s-change-from-phabricator for reference of what we need.

You can use Joshua Root <jmr@macports.org>, thanks.

This revision was landed with ongoing or failed builds.Jun 24 2022, 9:26 AM
This revision was automatically updated to reflect the committed changes.