Skip to content

Fix asan stack-use-after-scope error (Alignment)

Rosen Matev requested to merge rmatev-fix-asan-alignment into master

Fix the following address sanitizer error when name is empty.

=================================================================
==348==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffd2fda3ff0 at pc 0x7f521b09c001 bp 0x7ffd2fda3c10 sp 0x7ffd2fda3c08
READ of size 1 at 0x7ffd2fda3ff0 thread T0
    #0 0x7f521b09c000 in Condition::toXml[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >, bool, int) const /workspace/build/LHCb/Det/DetDesc/src/Lib/Condition.cpp:44
    #1 0x7f51fac0d5b0 in WriteAlignmentConditionsTool::write(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const /workspace/build/Alignment/Alignment/AlignTrTools/src/WriteAlignmentConditionsTool.cpp:229
    #2 0x7f51fac0e30d in WriteAlignmentConditionsTool::write() const /workspace/build/Alignment/Alignment/AlignTrTools/src/WriteAlignmentConditionsTool.cpp:195

Quoting @graven:

I suspect that this is due to the type of registry()->name() being const std::string&, which case the string literal "Condition" must be turned into the same type (as it is a trinary), which generates a temporary string, and then the view picks up that temporary instead of the literal from which the temporary is made....

See discussion at 029a8a4a (comment 3431695)

Merge request reports