In the following context.
`data` is a `uint8_t*` representing sequence of bytes.
`Col` in a std::vector containing some `uint64_t`.
Task: just to copy the `uint64_t` into the `data` under assumption, that before copy is the `data` empty but allocated.
1 2 3 4 5 6
|
uint64_t* ptr = reinterpret_cast<uint64_t*>(data);
printf("before: pointer to write: %p\n", data);
printf("before: ptr : %p\n", ptr);
std::copy(col.begin(), col.end(), ptr);
printf("after : pointer written : %p\n", data);
printf("after : ptr : %p\n", ptr);
|
Output:
before: pointer to write: 0x55fdd1493084
before: ptr : 0x55fdd1493084
after : pointer written : 0x100000000
after : ptr : 0x55fdd1493084
A bit Observation: As we know if we run this program many times, 0x55fdd1493084 will keep changing. BUT 0x100000000 this one always reminds here every time!
So I could not find the bug, do you have ideas? If you need more information, just tell me.
---------------------------------------------------------------------------------
Edit1 as Example
if using `std::vector<uint64_t> row {3, 2, 1, 4, 5, 6, 7, 8, 9, 257};`
We can have following things in `ptr` but nothing defined in `data`.
ptr has value 3, ptr has in pointer 0x55fdd1493084
ptr has value 2, ptr has in pointer 0x55fdd149308c
ptr has value 1, ptr has in pointer 0x55fdd1493094
ptr has value 4, ptr has in pointer 0x55fdd149309c
ptr has value 5, ptr has in pointer 0x55fdd14930a4
ptr has value 6, ptr has in pointer 0x55fdd14930ac
ptr has value 7, ptr has in pointer 0x55fdd14930b4
ptr has value 8, ptr has in pointer 0x55fdd14930bc
ptr has value 9, ptr has in pointer 0x55fdd14930c4
ptr has value 257, ptr has in pointer 0x55fdd14930cc
Edit 2:
Peter87 has right. The allocated space is not enough and some part is overwritten.
Thanks all.