代码实现读取文件(包含大量url)的函数,每个url都通过“evhttp_uri_parse”获取主机和路径。但它有一个错误,evhttp_uri_parse解析失败,返回NULL。可能的原因是堆栈溢出。堆栈溢出(关于“evhttp_uri_parse”)
FILE *fp=fopen(argv[1],"rb");
if(NULL==fp)
{
printf("open url_file is error %d::%s\n",errno,strerror(errno));
return 0;
}
char url_buf[2048];
memset(url_buf,'\0',sizeof(url_buf));
fgets(url_buf,sizeof(url_buf),fp);
while(!feof(fp))
{
if(strlen(url_buf)>1)
{
printf("url_buf::%s",url_buf);
#if 1
struct evhttp_uri *ev_uri=NULL;
ev_uri=evhttp_uri_parse(url_buf);
if(ev_uri==NULL)
{
printf("parse uri error::%d,%s\n",errno,strerror(errno));
}
const char *host=evhttp_uri_get_host(ev_uri);
const char *path=evhttp_uri_get_path(ev_uri);
printf("query host::%s,path::%s\n",host,path);
evhttp_uri_free(ev_uri);
#endif
}
memset(url_buf,'\0',sizeof(url_buf));
fgets(url_buf,sizeof(url_buf),fp);
}
fclose(fp);
您是否有触发错误的特定URL? – tripleee 2015-02-11 06:37:55
NO。一切都是一般的。 – sanwuhai 2015-02-11 06:46:05
'if(fp == NULL)'之后的'printf()'中的引号放错位置;你想要在换行符('\ n')后面加上关闭引号。错误消息通常应打印到标准错误,而不是标准输出。 – 2015-02-11 07:02:15