C++ Valgrind正在报道;使用大小为4”的未初始化值;使用strlen时

C++ Valgrind正在报道;使用大小为4”的未初始化值;使用strlen时,c++,raspberry-pi,valgrind,C++,Raspberry Pi,Valgrind,我想在覆盆子皮上用Valgrind。我正在分析以下程序: #include <string> #include <cstring> int main() { std::string blaat = "blaat"; const char * buf = blaat.c_str(); size_t l = 0; l = strlen(buf); printf("string size %u\n"

我想在覆盆子皮上用Valgrind。我正在分析以下程序:

#include <string>
#include <cstring>

int main() {
    std::string blaat = "blaat";
    const char * buf = blaat.c_str();
    size_t l = 0;
    l = strlen(buf);
    printf("string size %u\n", l);
}
分析(valgrind-3.16.1):

结果:

==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4866210: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x48662DC: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so)
==29572==
==29572== Use of uninitialised value of size 4
==29572==    at 0x4AABF6C: _itoa_word (_itoa.c:179)
==29572==    by 0x4AB0727: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AABF74: _itoa_word (_itoa.c:179)
==29572==    by 0x4AB0727: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAF8FC: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAF99C: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAFA00: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAFA7C: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)

一旦我使用“strlen”,Valgrind似乎会对未初始化的值发出警告。为什么?

如果您使用表示大小t的
%zu
,而不是表示无符号int的
%u
,这有关系吗?或者,
static\u cast(l)
。这两种选择都没有改变Valgrind的输出-仍然会收到警告如果你想让它们静音:这就是glibc在ARM上的工作方式,我一直都会收到这种错误。我认为这是出于性能原因。页面总是以4个字节的倍数对齐,因此通常一次检查4个字节以查找
strlen()
。将valgrind抑制作为一种解决方法。strlen的输出用作sendbuffer(数据,sz)函数的参数。现在Valgrind还将报告此函数正在使用统一化字节。因此,我必须将sendbuffer添加到抑制文件中,而不是将strlen添加到抑制文件中。然而,这些函数是我想要检查的。
valgrind --leak-check=yes ./a.out
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4866210: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x48662DC: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so)
==29572==
==29572== Use of uninitialised value of size 4
==29572==    at 0x4AABF6C: _itoa_word (_itoa.c:179)
==29572==    by 0x4AB0727: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AABF74: _itoa_word (_itoa.c:179)
==29572==    by 0x4AB0727: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAF8FC: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAF99C: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAFA00: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)
==29572==
==29572== Conditional jump or move depends on uninitialised value(s)
==29572==    at 0x4AAFA7C: vfprintf (vfprintf.c:1637)
==29572==    by 0x4AB646F: printf (printf.c:33)
==29572==    by 0x1088F: main (test.c:10)