Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory sanitizer gives spurious error? #805

Closed
nathansalwen opened this issue May 2, 2017 · 2 comments
Closed

memory sanitizer gives spurious error? #805

nathansalwen opened this issue May 2, 2017 · 2 comments

Comments

@nathansalwen
Copy link

Hi,

It is possible that I misunderstand C++ order of execution but I receive an incomprehensible (to me) uninitialized data error with following code. I am using clang 4.0 on Ubuntu 17.04

$ cat foo.cpp
#include
#include

const char * foo[] =
{
"AAA",
"BBB"
};

const int numfoo = sizeof(foo)/sizeof(const char *);

typedef std::map<int, int> other_map;
class bar : other_map
{
public:
bar(const char * b[], int numb)
{
for (int i = 0; i < numb; i++)
{
std::cout << b[i] << std::endl;
}
}
};

bar c(foo, numfoo);

int main(int argc, char** argv) {
return 0;
}
$ clang -g -fsanitize=memory foo.cpp -lstdc++
$ ./a.out
Uninitialized bytes in __interceptor_memcmp at offset 236 inside [0x7ffc47b0e0c0, 256)
==19320==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x7fe423328e75 in std::ctype::_M_widen_init() const (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb6e75)
#1 0x7fe423384b87 in std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x112b87)
#2 0x490b41 in bar::bar(char const**, int) /home/nks/foo.cpp:20:31
#3 0x41a624 in __cxx_global_var_init.2 /home/nks/foo.cpp:25:5
#4 0x41a67d in _GLOBAL__sub_I_foo.cpp /home/nks/foo.cpp
#5 0x49209c in __libc_csu_init (/home/nks/a.out+0x49209c)
#6 0x7fe42238137f in __libc_start_main /build/glibc-cxyGtm/glibc-2.24/csu/../csu/libc-start.c:247
#7 0x41a6a9 in _start (/home/nks/a.out+0x41a6a9)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb6e75) in std::ctype::_M_widen_init() const
Exiting
$ clang --version
clang version 4.0.0-1ubuntu1 (tags/RELEASE_400/rc1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@chefmax
Copy link

chefmax commented May 2, 2017

To use MSan with C++ you need to use MSanitized libc++ (see https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo for details).

@nathansalwen
Copy link
Author

Thank you! I see I missed it in the Wiki.

@chefmax chefmax closed this as completed May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants