a
is an array, not a pointer. On the stack, there's a significant difference, which I describe in my answer here.a
is higher thanb
on the stack, so when you copy10
bytes froma
tob
, you have gone5
bytes off the end ofb
and replaced the first5
bytes ofa
. Note that this specific behavior is highly dependent on the compiler flags and the compiler version, and is generally speaking undefined.- As an additional note, you have not printed the address of
a
, which is what I assume you meant bypointer
. You have instead printed the value stored there.
Memcpy change the pointers?
-
21-07-2023 - |
Question
My task is to exploit a program which has two lines of code of memcpy. So I'm now studying memcpy and just found this.
int main() {
char a[10] = "123456789";
cout<<a<<endl;
char b[5];
memcpy(b, a, 10);
cout<<a<<endl;
cout<<a-5<<endl;
cout<<b<<endl;
}
and the output will be:
123456789
6789
123456789
123456789
Any idea Why the pointer of a changed here?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow