MemorySanitzer 警告在 `struct stat` 中使用未定义的内存;不过,我确实检查了 `stat` return 值

MemorySanitzer warns of use of undefined memory in `struct stat`; I do check the `stat` return value, though

        struct stat st;
        if (stat(python_pkgdir, &st)) {
            qd_error_errno(errno, "Cannot find Python library path '%s'", python_pkgdir);
            return NULL;
        } else if (!S_ISDIR(st.st_mode)) {  // dispatch.c, line 99
            qd_error(QD_ERROR_RUNTIME, "Python library path '%s' not a directory", python_pkgdir);
            return NULL;
        }
==2028==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x56b3c3 in qd_dispatch /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/src/dispatch.c:99:20
    #1 0x4c2346 in main_process /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/router/src/main.c:92:16
    #2 0x4c05d8 in main /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/router/src/main.c:369:9
    #3 0x7f398fd39b74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
    #4 0x43fdbd in _start (/__w/qpid-dispatch/qpid-dispatch/qpid-dispatch/build/router/qdrouterd+0x43fdbd)

  Uninitialized value was created by an allocation of 'st' in the stack frame of function 'qd_dispatch'
    #0 0x56ab90 in qd_dispatch /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/src/dispatch.c:77

SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/src/dispatch.c:99:20 in qd_dispatch

我的代码哪里出了问题?据我所知,我只在调用 stat 成功时触摸 st.st_mode。我正要归咎于我的编译器、杀毒软件或 glibc 中的错误。

我唯一能想到的就是稍微解压缩 if。做一个 if ( ... != 0) return,删除不需要的 else(由于之前的 return),使代码更常规。不过,这不会改变意思。

MemorySanitizer 不会检测程序执行中涉及的所有代码。它无法检测外部库,包括标准库或内核代码。

MemorySanitizer requires that all program code is instrumented. This also includes any libraries that the program depends on, even libc. Failing to achieve this may result in false reports.

Full MemorySanitizer instrumentation is very difficult to achieve. To make it easier, MemorySanitizer runtime library includes 70+ interceptors for the most common libc functions.

显然 libc 有 70 多个函数,所以误报是不可避免的。