Code Monkey home page Code Monkey logo

Comments (1)

techiethink avatar techiethink commented on August 16, 2024

错误信息如下:
#0 0x00007f7eef07a837 in raise () from /lib64/libc.so.6
#1 0x00007f7eef07be7a in abort () from /lib64/libc.so.6
#2 0x00007f7eef9b6192 in __gnu_cxx::__verbose_terminate_handler () at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007f7eef9b4076 in __cxxabiv1::__terminate(void (*)()) () at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007f7eef9b40b1 in std::terminate () at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007f7eef9b42f3 in __cxxabiv1::__cxa_throw (obj=, tinfo=0x7f7eefc99690 ,
dest=0x7f7eef9b2500 std::bad_alloc::~bad_alloc()) at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00007f7eef9b47bc in operator new (sz=280366331249121) at ../../../../libstdc++-v3/libsupc++/new_op.cc:54
#7 0x00007f7eefa4233b in std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_mutate (
this=this@entry=0x7f7ee97f1e40, __pos=140183165624672, __len1=__len1@entry=0,
__s=0x7f7edc0f5e00 "[{"symbol":"ETHBTC","price":"0.02928100"},{"symbol":"LTCBTC","price":"0.01518500"},{"symbol":"BNBBTC","price":"0.00387090"},{"symbol":"NEOBTC","price":"0.00149900"},{"symbol":"QTUMETH","price":"0.0133"...,
__len2=16384) at /data/software/gcc-8.3.0/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:310
#8 0x00007f7eefa438d3 in std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_append (
this=0x7f7ee97f1e40, __s=, __n=)
at /data/software/gcc-8.3.0/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:287
#9 0x00000000004a938a in BinaCPP::curl_cb (content=0x7f7edc0f5e00, size=1, nmemb=16384, buffer=0x7f7ee97f1e40)
at /data/home/aron/topex.code.chuanxi/ygw-server/app/exchange-btcusdt/binance/binacpp.cpp:1768
#10 0x00007f7ef1170960 in Curl_client_write () from /lib64/libcurl.so
#11 0x00007f7ef118fb65 in inflate_stream () from /lib64/libcurl.so
#12 0x00007f7ef118ff6d in Curl_unencode_gzip_write () from /lib64/libcurl.so
#13 0x00007f7ef118a584 in Curl_httpchunk_read () from /lib64/libcurl.so
#14 0x00007f7ef1184b57 in Curl_readwrite () from /lib64/libcurl.so
#15 0x00007f7ef118ea5f in multi_runsingle () from /lib64/libcurl.so
#16 0x00007f7ef118f3b1 in curl_multi_perform () from /lib64/libcurl.so
#17 0x00007f7ef1186623 in curl_easy_perform () from /lib64/libcurl.so
#18 0x00000000004a972f in BinaCPP::curl_api_with_header (url=..., str_result=..., extra_http_header=..., post_data=..., action=...)
at /data/home/aron/topex.code.chuanxi/ygw-server/app/exchange-btcusdt/binance/binacpp.cpp:1825
#19 0x00000000004a943a in BinaCPP::curl_api (url=..., result_json=...)
at /data/home/aron/topex.code.chuanxi/ygw-server/app/exchange-btcusdt/binance/binacpp.cpp:1785
#20 0x00000000004a27dd in BinaCPP::get_allPrices (json_result=...)
at /data/home/aron/topex.code.chuanxi/ygw-server/app/exchange-btcusdt/binance/binacpp.cpp:95
#21 0x00000000004a299f in BinaCPP::get_price (symbol=0x7f7ee9ff2ff0 "BTCUSDT")
at /data/home/aron/topex.code.chuanxi/ygw-server/app/exchange-btcusdt/binance/binacpp.cpp:125

修正方法:
CURLOPT_WRITEDATA这个选项在C++中使用时就要注意了,
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WRITEDATA, void *pointer);
这里pointer必须是struct,不能是类class,否则会有莫名奇怪的错误
这样的后果是,最后下载的文件长度与原有长度不符,使用md5sum计算得到的校验值与标准值不符。这证明是错误的文件

请参考: https://blog.csdn.net/hqbvqv/article/details/70187608

参考代码:
size_t
BinaCPP::curl_cb( void content, size_t size, size_t nmemb, void response )
{
BinaCPP_logger::write_log( "BinaCPP::curl_cb " ) ;

//buffer->append((char*)content, size*nmemb);

size_t realsize          = size * nmemb;
struct MemoryStruct* mem = (struct MemoryStruct *)response;

char *ptr = (char*) realloc((void*)mem->memory, mem->size + realsize + 1);
if(ptr == NULL) {
	/* out of memory! */ 
	printf("not enough memory (realloc returned NULL)\n");
	return 0;
}

mem->memory = ptr;
memcpy(&(mem->memory[mem->size]), content, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;

BinaCPP_logger::write_log( "<BinaCPP::curl_cb> done" ) ;

return realsize;

}

from binacpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.