- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行 Valgrind,但出现以下错误(这不是唯一一个):
==21743== Conditional jump or move depends on uninitialised value(s)
==21743== at 0x4A06509: index (mc_replace_strmem.c:164)
==21743== by 0x33B7CBB3CD: gaih_inet (in /lib64/libc-2.5.so)
==21743== by 0x33B7CBD629: getaddrinfo (in /lib64/libc-2.5.so)
==21743== by 0x401A5F: tunnelURL (proxy.c:336)
==21743== by 0x40142A: client_thread (proxy.c:194)
==21743== by 0x33B8806616: start_thread (in /lib64/libpthread-2.5.so)
==21743== by 0x33B7CD3C2C: clone (in /lib64/libc-2.5.so)
tunnelURL()
函数看起来像这样(C 代码):
char * tunnelURL(char *url) {
char * a = strstr(url, "//");
a += 2;
char * path = strstr(a, "/");
char host[256];
strncpy (host, a, strlen(a)-strlen(path));
/*
* The following is courtesy of Beej's Guide
*/
int status;
int proxySocketFD;
struct addrinfo hints;
struct addrinfo *servinfo; // will point to the results
memset(&hints, 0, sizeof(hints)); // make sure the struct is empty
hints.ai_family = AF_INET; // don't care IPv4 or IPv6
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
hints.ai_flags = AI_PASSIVE; // fill in my IP for me
if ((status = getaddrinfo(host, "80", &hints, &servinfo)) != 0) {
perror("getaddrinfo() fail");
exit(1);
}
// create socket
if ((proxySocketFD = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol)) == -1) {
perror("proxy socket() fail");
exit(1);
}
// connect
if (connect(proxySocketFD, servinfo->ai_addr, servinfo->ai_addrlen) != 0) {
printf("connect() fail");
exit(1);
}
// construct request
char request[strlen(path) + strlen(host) + 26];
sprintf(request, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", path, host);
printf("%s", request);
// send request
send(proxySocketFD, request, strlen(request), 0);
// receive response
int i = 0;
int amntRecvd = 0;
char *pageContentBuffer = (char*) malloc(4096 * sizeof(char));
while ((amntRecvd = recv(proxySocketFD, pageContentBuffer + i, 4096, 0)) > 0) {
i += amntRecvd;
realloc(pageContentBuffer, i * 4096 * sizeof(char));
}
// close proxy socket
close(proxySocketFD);
// deallocate memory
freeaddrinfo(servinfo);
return pageContentBuffer;
}
if
声明与
getaddrinfo()
函数调用。我不确定我还没有初始化什么。我传入的字符串“应该”已经设置好了。我打印出来就好了。我还收到与同一行代码对应的另一个错误:
==21743== Use of uninitialised value of size 8
==21743== at 0x33B7D05816: __nscd_cache_search (in /lib64/libc-2.5.so)
==21743== by 0x33B7D0438B: nscd_gethst_r (in /lib64/libc-2.5.so)
==21743== by 0x33B7D04B26: __nscd_gethostbyname2_r (in /lib64/libc-2.5.so)
==21743== by 0x33B7CE9F5E: gethostbyname2_r@@GLIBC_2.2.5 (in /lib64/libc-2.5.so)
==21743== by 0x33B7CBC522: gaih_inet (in /lib64/libc-2.5.so)
==21743== by 0x33B7CBD629: getaddrinfo (in /lib64/libc-2.5.so)
==21743== by 0x401A5F: tunnelURL (proxy.c:336)
==21743== by 0x40142A: client_thread (proxy.c:194)
==21743== by 0x33B8806616: start_thread (in /lib64/libpthread-2.5.so)
==21743== by 0x33B7CD3C2C: clone (in /lib64/libc-2.5.so)
最佳答案
您没有使用 realloc()
正确。 realloc()
可能会移动分配的块,并返回块的新地址 - 因此您需要将该返回值分配给 pageContentBuffer
(如果它不是 NULL
)。
关于c - 多个 valgrind 错误 : Conditional jump or move depends on uninitialised value(s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2679661/
所以我得到了这段代码,我应该将其放入我的代码中,该代码使用 getopt_long() 函数从命令行读取选项,并通过切换菜单传递它们。问题在于该函数,如果我不初始化 long_opts 的值,我会收到
现在,首先,我已经在该站点上阅读了其他答案,以及有关 jackson 序列化的其他答案,但是它们都提供了忽略null字段的方法。但是,在Java中,int不能是null。 我正在尝试将Java对象Ob
这个 valgrind 输出让我感到困惑,因为它似乎没有引用我的代码,而且我在使用 STL 编写的多个程序中都得到了它,尽管没有 HEAP SUMMARY 错误: $ valgrind -v --le
我写了一个小的 c 程序,它获取 3 个名称作为输入,然后将这三个值存储到一个节点。这三个值(名称)存储在数组 JOHNJAKEMATT 中,每个名称有 4 个字符。结果节点如下所示: /* poin
我正在写一个 linux 模块,这里是代码片段。它提示变量的统一化使用,但我想我已经检查过了在使用它之前有足够的检查。我认为这可能是相关的ERR_PTR 和 PTR_ERR 宏,但我不知道为什么。有人
我是 IOS 开发和处理内存泄漏的新手。在我的项目中,在分析项目时我遇到了一些内存泄漏。但是我无法在下面的代码中修复下面的逻辑错误。 CGRect labelframe; if ([questonmo
我分配一个二维数组并使用 memset 用零填充它。 #include #include #include void main() { int m=10; int n =10;
我有以下程序 http://ideone.com/1RPs8E .它使用可变参数函数 tlog 将在日志文件中打印一行。它接收打印行的级别、文件名、一行和调试信息的函数以及 printf 的格式和参数
我们正在尝试建立一个哈希表和一些用于设置、获取和删除表中值的过程。我们在第 35 行和第 53 行遇到“条件跳转或移动取决于未初始化的值”问题。 ==23720== Conditional jump
我正在尝试用 C 语言编写自己的 shell。下面的代码适用于没有管道的命令,但不适用于其他情况。 使用 --trace-children=yes 和 --track-origins=yes 运行 v
如何在 valgrind 的输出中抑制这个错误? ==16727== 1 errors in context 2 of 18: ==16727== Conditional jump or move d
我一直在使用 Valgrind 来查找我的代码中的内存泄漏,虽然没有发现内存泄漏,但报告了一些错误,所有这些错误都源于单个函数/类方法: ==17043== ERROR SUMMARY: 10100
该代码将编译并运行,并创建预期的输出,除非运行valgrind时才会出现这些内存泄漏。以下代码在Visual Studio上运行,不会出现任何警告或错误。 所以我的问题是,此内存泄漏发生在哪里?我是C
我正在为学校用 C 语言编写一个简约的 shell。它工作正常,但使用 Valgrind 我收到此错误,我无法弄清楚我做错了什么。我在程序开始时得到它: ==9396== Conditional ju
Valgrind 告诉我两个我无法解决的错误。我在以下函数 unplug_set 中收到“条件跳转或移动取决于未初始化的值”错误消息。是因为 NULL 检查吗?该函数应该从双链表中拔出元素。 void
这是我在第一节编程基础课后遇到的问题之一 gets() 工作正常(我认为),但“cin”拒绝工作 int main(void) { char *s1, *s2; puts("Enter
当我将我的项目与库的静态版本链接时,VALGRIND 开始报告错误编号“条件跳转或移动取决于未初始化的值”错误。问题是项目本身除了空的主函数外什么都没有,所以肯定是库的问题。 库的共享二进制文件和静态
我正在尝试编写一个将新结构添加到链表中的函数。无论我做什么,Valgrind 都会不断给我这个错误。这是代码: /* Stores a new address record to the linked
这是一些 Valgrind 日志的一部分: ==1652== Conditional jump or move depends on uninitialised value(s)==1652==
我在 valgrind 中遇到错误,不知道哪里出了问题。错误是:valgrind 输出: ==1112== Conditional jump or move depends on uninitiali
我是一名优秀的程序员,十分优秀!