C/C++ llvm10 memory sanitizer error at std::ostream::operator<<

a.lunkov

New Member


Messages: 1

Hello!

I created this simple source file:
C++:
#include <iostream>

int main(){
    std::cout << "TEST" << std::endl;
    return 0;
}
Compiled this file with devel/llvm10:
clang++10 -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -Wall -Wextra -pedantic -g -I/usr/include test1.cpp -o test1

I got the following error while running the executable:
Memory sanitizer error
Code:
==32903==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x10b1346 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) /usr/include/c++/v1/ostream:723:13
    #1 0x10b0604 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) /usr/include/c++/v1/ostream:865:12
    #2 0x10b022b in main /home/qqq/11_sanitizer/test1.cpp:13:12
    #3 0x10578da in _start /usr/src/lib/csu/amd64/crt1.c:76:7

  Uninitialized value was created by an allocation of '__s' in the stack frame of function '_ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m'
    #0 0x10b0cf0 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) /usr/include/c++/v1/ostream:717

SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/include/c++/v1/ostream:723:13 in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long)
Exiting
Maybe I'm using the memory sanitizer incorrectly, tell me, please, what is my mistake?

My system is FreeBSD 12.1-RELEASE.
 

Paul Floyd

Active Member

Reaction score: 27
Messages: 100

This looks like a false positive. I get the same with clang built from git, but no error with Valgrind.
 
Top