c++ - Stack around variable was corrupted (Converting long long to byte array) -
when gets end of function, bombs "stack around variable corrupted" variable keybytes2. not sure missing why problem. using nvcc compiler.
char keybytes2[7]; long long unsigned lkey; lkey = 32428228256948131; //convert long long byte array (int = 0; < 8; ++i) { keybytes2[i] = ((lkey) >> 8 * i) & 0xffu; }
char keybytes2[7];
this allocates 7 bytes, not 8. in loop access keybytes2[7]
, i.e. eighth byte of array. out-of-range access , undefined behavior.
Comments
Post a Comment