[PATCH] D107273: [llvm-objcopy] IHexELFBuilder::addDataSections - fix evaluation ordering static analyzer warning
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 2 06:34:10 PDT 2021
RKSimon created this revision.
RKSimon added reviewers: evgeny777, rupprecht, jhenderson.
Herald added subscribers: manas, steakhal, ASDenysPetrov, abrachet, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware, emaste.
Herald added a reviewer: alexander-shaposhnikov.
RKSimon requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.
As detailed on https://pvs-studio.com/en/blog/posts/cpp/0771/ and raised on D62583 <https://reviews.llvm.org/D62583>, the SecNo++increment is not guaranteed to occur before the second use of SecNo in the same addSection() call.
This patch pulls out the increment and adjusts the second use of SecNo accordingly.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107273
Files:
llvm/tools/llvm-objcopy/ELF/Object.cpp
Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -1342,13 +1342,15 @@
if (R.HexData.empty())
continue;
RecAddr = R.Addr + SegmentAddr + BaseAddr;
- if (!Section || Section->Addr + Section->Size != RecAddr)
+ if (!Section || (Section->Addr + Section->Size) != RecAddr) {
// OriginalOffset field is only used to sort section properly, so
// instead of keeping track of real offset in IHEX file, we use
// section number.
Section = &Obj->addSection<OwnedDataSection>(
- ".sec" + std::to_string(SecNo++), RecAddr,
- ELF::SHF_ALLOC | ELF::SHF_WRITE, SecNo);
+ ".sec" + std::to_string(SecNo), RecAddr,
+ ELF::SHF_ALLOC | ELF::SHF_WRITE, SecNo + 1);
+ ++SecNo;
+ }
Section->appendHexData(R.HexData);
break;
case IHexRecord::EndOfFile:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107273.363467.patch
Type: text/x-patch
Size: 1026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210802/82692a7b/attachment.bin>
More information about the llvm-commits
mailing list