Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
added 32 characters in body
Source Link
Jabberwocky
  • 51.3k
  • 18
  • 71
  • 127

You're copying into the wrong address.

pMyStringAdresspMyStringAdress is a pointer that holds the heap address returned by VirtualAllocVirtualAlloc.

But you used &pMyStringAdress&pMyStringAdress (the address of the pointer variable on the stack) both when printing and in memcpy. That writes past the pointer variable itself and trashes the stack -> "Run-Time Check Failure #2 … stack … was corrupted."

- Fixes

Use pMyStringAdress, hence the message (no &) when printing and copying."Run-Time Check Failure #2 … stack … was corrupted."

Free with VirtualFree when done.Fixes

Minor: use the right printf specifiers.

  • Use pMyStringAdress (no &) when printing and copying.
  • Free with VirtualFree when done.
  • Minor: use the right printf specifiers.

You're copying into the wrong address.

pMyStringAdress is a pointer that holds the heap address returned by VirtualAlloc.

But you used &pMyStringAdress (the address of the pointer variable on the stack) both when printing and in memcpy. That writes past the pointer variable itself and trashes the stack -> "Run-Time Check Failure #2 … stack … was corrupted."

- Fixes

Use pMyStringAdress (no &) when printing and copying.

Free with VirtualFree when done.

Minor: use the right printf specifiers.

You're copying into the wrong address.

pMyStringAdress is a pointer that holds the heap address returned by VirtualAlloc.

But you used &pMyStringAdress (the address of the pointer variable on the stack) both when printing and in memcpy. That writes past the pointer variable itself and trashes the stack, hence the message "Run-Time Check Failure #2 … stack … was corrupted."

Fixes

  • Use pMyStringAdress (no &) when printing and copying.
  • Free with VirtualFree when done.
  • Minor: use the right printf specifiers.
Source Link
muraya
  • 67
  • 10

You're copying into the wrong address.

pMyStringAdress is a pointer that holds the heap address returned by VirtualAlloc.

But you used &pMyStringAdress (the address of the pointer variable on the stack) both when printing and in memcpy. That writes past the pointer variable itself and trashes the stack -> "Run-Time Check Failure #2 … stack … was corrupted."

- Fixes

Use pMyStringAdress (no &) when printing and copying.

Free with VirtualFree when done.

Minor: use the right printf specifiers.