c++ - uint32_t variable is strange changing -
i have simple code:
#define num_ua_sock 100 typedef struct _ua_request { string full_url; uint32_t url_adler32 ; tcpsocket sock_ua ; uint32_t status_flag ; // ref enum status } ua_request ; ua_request glb_array__ua_req[ num_ua_sock ] ; void handle_ua_sock_ready( uint32_t ii ) { string _req_mstr; byte*request = (byte*) _req_mstr.c_str() ; byte*pcrlf = null ; ua_request*ar = glb_array__ua_req ; // request ua int32_t nrcv ; printf("index = %lu\n", ii); tcpsocket sock = ar[ii].sock_ua; nrcv = sdlnet_tcp_recv( sock , request , maxlen ) ; printf("after index = %lu\n", ii); } the ii variable in begin of handle_ua_sock_ready() func has 0 value. after invoking nrcv = sdlnet_tcp_recv( sock , request , maxlen ) ; line becomes have big value instance 1852397344. single-threaded app. i'm using vs 2010, sdl, sdl_net libraries. ps: when compiled under linux, works fine.
you're passing in request sdlnet_tcp_recv function , telling function request points buffer of size maxlen. request comes casting away constness buffer of empty std::string wrong.
you want vector
std::vector<unsigned char> request; request.resize(maxlen); ... nrcv = sdlnet_tcp_recv( sock , request.data() , request.size() ) ;
Comments
Post a Comment