(Not) Pointer Adjusting ruining my day and the heap? (C++)
-edit2- I was going down the wrong path. I solved it by correcting one typo and adding one line to fix an oversight that allowed me to write 4 bytes to many over an array.
-edit- maybe i am running through a wrong path. Maybe VS is showing me incorrect data but still runs the code properly (after all my code does show the correct name). But i have no idea where else my heap corruption could come from.
I havent notice any problems or incorrect data. But i have notice random crashes and suggestions that its caused by corrupting the heap.
I looked into something and this is what i notice. I have a class at address 0x00216e98. In my watch i can see the data correctly and below you can see the name ptr is 21bc00. I return the ptr as a base class (lets call it Base) which is inserted into a deque. As you can see in the deque (ls) it has one element and the first element is the correct pointer (i thought it may adjust but i guess not. But maybe it is but.....).
However the members it holds is COMPLETELY INCORRECT cdcdcd00 does not look like a valid name ptr to me and does not match to the ptr below. Also when my code is ran i somehow get the correct name and such so i dont know whats going on/wrong. It could be dynamic_cast magic but anyways if i am still grabbing the correct data i dont know how i am corrupting the heap (in both gcc and msvc).
I'll note i have diamond inheritance to the 'Base' class however li开发者_JS百科ke i said i am still pulling the correct data and i am not using virtual with base.
If you are using linux you might be able to use Valgrind. This is an exellent tool for finding heap related issues.
In debug mode cdcdcdcd is deleted uninitialized memory that the debug heap is marking for you.
If you see that, you are using a pointer to a deleted structure. memory that was allocated but never given a value.
精彩评论