下面是我的示例代码:
int function1(unsigned char *out, int length){
unsigned long crypto_out_len = 16;
unsigned char crypto_out[16] = {0};
.......
//produces 16 bytes output & stores in crypto_out
crypto_function(crypto_out, crypto_out_len);
//lets say crypto_output contents after are : "abcdefghijklmnop"
.......
memcpy(out, crypto_out,length);
return 0;
}
function2(){
unsigned char out[10] = {0};
function1(out, 10);
std::pair<unsigned char *,int> map_entry;
map_entry.first = out;
map_entry.second = 10;
}
现在,map_entry.first 应该包含:“abcdefghij”,对吧?
但它包含“abcdefghij#$%f1^”,一些与之相关的垃圾。我应该如何避免这种意外行为,以便map_entry.first
准确包含“abcdefghij”。