2

这是一个重现的最小示例-

#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";
}

用 - 编译它clang++ lol.cpp -g -fsanitize=memory然后运行它会产生 -

==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

指向-if(!names) {线。也发生-stdlib=libc++

4

0 回答 0