Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  
Evil Steve


You know you're in for trouble, when your memory manager corrupts memory [sad]

To be honest, I thought my stack walking code worked too well. I had a lovely off-by-one error in the following code:

unsigned char byBuffer[sizeof(IMAGEHLP_SYMBOL64) + Allocation::cnBufferSize];
DWORD64 dwDisplacement;
memset(pSymbol, 0, sizeof(IMAGEHLP_SYMBOL64) + Allocation::cnBufferSize);
pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
pSymbol->MaxNameLength = Allocation::cnBufferSize;
if(!SymGetSymFromAddr64(GetCurrentProcess(), theStackFrame.AddrPC.Offset, &dwDisplacement, pSymbol))
strcpy(pAllocation->szFunc, "??");
strcpy(pAllocation->szFunc, pSymbol->Name);

Since if SymGetSymFromAddr64() runs out of space, it doesn't NULL terminate the shitting string. It just so happens that the next byte in memory was NULL, which was causing strcpy() to copy 257 bytes (256+null) into a buffer big enough for 255+null. Wonderful.
On the plus side, my memory manager detected the corruption (I got an assertion saying that a memory sentinal was damaged when I ran this code: {std::map m;}).

In other news, my string hashing "ID" class is working, and has a debug helper doohicky for detecting collisions. Hooraj!
Sign in to follow this  


Recommended Comments

Guest Anonymous Poster


How do you do it? How do you make your journal so dull?

Share this comment

Link to comment
Original post by rick_appleton
Why aren't you using strncpy? That would have avoided that problem.
Because I thought that the buffer would always be <= 256 bytes long, since I passed that to the function. Oh well, I'll know in future.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!