Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openpower-pels: fru-identity: fix crash in setPartNumber
On newer libstdc++ implementations, the following backtrace is observed: ``` #2 0x00007ffff7a578b7 in abort () from /usr/lib64/libc.so.6 #3 0x00007ffff7cda2af in std::__glibcxx_assert_fail(char const*, int, char const*, char const*) () from /usr/lib/gcc/x86_64-pc-linux-gnu/14/libstdc++.so.6 #4 0x000055555556ac6f in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::front (this=0x7fffffffd790) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/basic_string.h:1315 #5 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::front (this=0x7fffffffd790) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/basic_string.h:1315 #6 openpower::pels::src::FRUIdentity::setPartNumber (this=this@entry=0x7fffffffd8a0, partNumber="") at ../extensions/openpower-pels/fru_identity.cpp:216 #7 0x000055555556ae12 in openpower::pels::src::FRUIdentity::FRUIdentity (this=this@entry=0x7fffffffd8a0, partNumber="", ccin="", serialNumber="") at ../extensions/openpower-pels/fru_identity.cpp:102 #8 0x0000555555562aaf in testHWCallout (pn="", ccin="", sn="", expectedPN="", expectedCCIN="", expectedSN="") at ../test/openpower-pels/fru_identity_test.cpp:97 #9 0x00005555555645b0 in FRUIdentityTest_CreateHardwareCalloutTest_Test::TestBody (this=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/basic_string.tcc:242 ``` Fix this by avoiding accessing `front()` when the part number string is empty. While there, do a minor performance optimization to avoid unnecessary string copies, by using `erase` instead of `substr`. Signed-off-by: Patrick Williams <[email protected]> Change-Id: I71cc195596def6ad0cd982e7294e2467beee987c
- Loading branch information