Abhinav Gauniyal
Abhinav Gauniyal

Reputation: 7574

Memory Sanitizer use-of-uninitialized-value with ifstream

Here's a minimal example to reproduce -

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main() {
    ifstream names("lol.txt");
    if(!names) {
        cerr << "Not found\n";
        return -1;
    }

    cout << "Done\n";
}

Compiling it with - clang++ lol.cpp -g -fsanitize=memory and then running it yields -

==2327==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55ece5b5f4c4 in main /home/agauniyal/lol.cpp:9:9
    #1 0x7f5ab5a45f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
    #2 0x55ece5ae3b99 in _start (/home/agauniyal/a.out+0x1ab99)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/agauniyal/lol.cpp:9:9 in main
Exiting

pointing to - if(!names) { line. Happens with -stdlib=libc++ as well.

Upvotes: 2

Views: 179

Answers (0)

Related Questions