diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2021-08-03 12:16:45 +0100 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2021-08-03 12:16:59 +0100 |
commit | 43ff058e78d9e4fa47080b61fc3811da80db1b3f (patch) | |
tree | d7a3e676f2e23ec155460ceb84977d325368e3e8 /llvm/tools/llvm-objcopy/ELF/Object.cpp | |
parent | e4dee762245d1fefc6bcae643ecc55063aef2e9c (diff) | |
download | llvm-43ff058e78d9e4fa47080b61fc3811da80db1b3f.zip llvm-43ff058e78d9e4fa47080b61fc3811da80db1b3f.tar.gz llvm-43ff058e78d9e4fa47080b61fc3811da80db1b3f.tar.bz2 |
[llvm-objcopy] IHexELFBuilder::addDataSections - fix evaluation ordering static analyzer warning
As detailed on https://pvs-studio.com/en/blog/posts/cpp/0771/ and raised on 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 (just for clarity) and replaces the second use of SecNo with a constant zero value (we're using stable_sort so the value isn't critical).
Differential Revision: https://reviews.llvm.org/D107273
Diffstat (limited to 'llvm/tools/llvm-objcopy/ELF/Object.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/ELF/Object.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp index ba91d08..6b632ae 100644 --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -1342,13 +1342,16 @@ void IHexELFBuilder::addDataSections() { 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. + // instead of keeping track of real offset in IHEX file, and as + // Object::sortSections() uses llvm::stable_sort(), we can just set to a + // constant (zero). 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, 0); + SecNo++; + } Section->appendHexData(R.HexData); break; case IHexRecord::EndOfFile: |