我已经阅读了关于此的所有答案,但我无法修复它。 Valgrind一直告诉我:
==9934== Conditional jump or move depends on uninitialised value(s)
==9934== at 0x4C2D2DB: __GI_strcat (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9934== by 0x402036: main (in /home/doge/Tarea3/http)
这是我的代码失败的时候:
// buffer which gets the file
char buf[1024];
//socket
struct sockaddr_in *remote;
// socket port
int sock;
// ALGP
int tmpres;
//ip as string
char *ip;
//final query
char *get;
// host -> url
char* host=url;
//resource (Ex index.html)
char *page;
page=PAGE;
char *ruta = NULL;
if(url_long>0){
ruta = (char *)malloc((url_long+12)*sizeof(char));
}
strcat(ruta,url);
if(command==1){
strcat(ruta,"GET.txt\0");
}
else if(command==2){
strcat(ruta,"POST.txt\0");
}
else if(command==3){
strcat(ruta,"HEAD.txt\0");
}
FILE *fp = fopen(ruta,"r");
memset(buf, 0, sizeof(buf)+1);
size_t nread=0;
之前声明了URL:
char *url=NULL;
if(url_long>0)
url = (char *)malloc((url_long+1)*sizeof(char));
显然,这导致我的服务器无法在客户端套接字中写入。我不知道为什么,但是当它与Valgrind一起运行时一切正常。 谢谢
编辑:使用--track-origin =运行Valgrind,这就是我所得到的:
==11366== Conditional jump or move depends on uninitialised value(s)
==11366== at 0x4C2D6EB: __GI_strcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11366== by 0x4020D6: main (in /home/doge/Tarea3/http)
==11366== Uninitialised value was created by a heap allocation
==11366== at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11366== by 0x401DFB: main (in /home/doge/Tarea3/http)