封顶libcurl在X字符之后返回
Capping libcurl return after X characters
cURL检索的页面大于5000个字符似乎在我的应用程序中导致分割错误。
//Includes etc.
#include "mainheader.h"
using namespace std;
using namespace boost;
//Buffer is defined right after the includes
char buffer [5000];
//cURL result to buffer, which is declared above.
void function_pt(void *ptr, size_t size, size_t nmemb, void *stream)
{
int n;
n=sprintf(buffer,"%s", ptr, size, nmemb, stream);
}
//Function to check one URL
void checkurl(char* thisurl)
{
//Start curl
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, thisurl);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, function_pt);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
我不能100%确定这是否是导致分割错误的原因,有可能任何包含多个换行符的返回都会导致分割错误(尚未能够测试)。但我假设缓冲区会自动切断5000个字符后返回的数据,但我想这是天真的我。我怎样才能确定是这样呢?
你的短跑线错了。您为格式字符串传递了太多参数。此外,您还可以使用snprintf,它类似于sprintf,但能够获取最大长度以防止缓冲区溢出。
相关文章:
- 了解在返回值之前和之后使用 EAX 的函数调用
- kill() 总是返回 0(成功),即使在子进程已经结束之后?
- 为什么我的类工作正常,即使在返回垃圾值作为赋值运算符和空复制构造函数的返回之后
- 如果语句之后,返回vs无能为力
- 移动了 QT 项目,重命名文件夹和项目名称,Moc'ing 返回"'-I'之后缺少值"
- C :Bool方法在COUT语句之后返回意外数字
- 可以在 main 的返回 0 语句之后调用任何函数吗?
- 为什么 queue:front() 的返回值在 queue::p op() 之后有效
- 返回从字符串末尾 (C++) 之后的位置开始的子字符串
- 我的程序返回整数值,但即使在显式类型转换之后也应该给出双值
- 为什么QDrag::target()在QDrag::exec()之后返回一个奇怪的地址
- std::queue::size() 可以在 size() == 0 的 pop() 之后返回一个巨大的数字
- 欧拉项目任务#8,代码在某个点之后开始返回错误的答案
- C++函数中返回语句之后的指令
- 在计算函数返回值之前或之后是否销毁了局部变量
- Strcat()在strcpy之后返回垃圾
- 如何在SIGTSTP之后返回shell
- 在自动销毁变量之前或之后创建的c++返回值
- 封顶libcurl在X字符之后返回
- GetIndices()会在CreateIndexBuffer()和SetIndices()之后返回相同的缓冲区指针吗?