Random Stack Pointers
-
When using the CMapXXX classes, you are supposed to pass in the address to a 'type' to receive the value at the key. It is even more interesting if you merely declare a pointer as a stack variable and pass that instead... In header file...
typedef CTypedPtrMap< CMapWordToPtr, WORD, WORD* > HandleMap;
class whatever { ... HandleMap m_HandleMap ... };
Then you perform a lookup like this, for example:BOOL WhatEver::DoesKeyExist(WORD wKey) { WORD *pDummy; :wtf: if( !m_HandleMap.Lookup(wKey, pDummy) ){ return FALSE; } return TRUE; }
Assuming it DOES find the key, where does the value stored at the key go ? What does pDummy actually point to ?Any sufficiently gross incompetence is nearly indistinguishable from malice.
-
When using the CMapXXX classes, you are supposed to pass in the address to a 'type' to receive the value at the key. It is even more interesting if you merely declare a pointer as a stack variable and pass that instead... In header file...
typedef CTypedPtrMap< CMapWordToPtr, WORD, WORD* > HandleMap;
class whatever { ... HandleMap m_HandleMap ... };
Then you perform a lookup like this, for example:BOOL WhatEver::DoesKeyExist(WORD wKey) { WORD *pDummy; :wtf: if( !m_HandleMap.Lookup(wKey, pDummy) ){ return FALSE; } return TRUE; }
Assuming it DOES find the key, where does the value stored at the key go ? What does pDummy actually point to ?Any sufficiently gross incompetence is nearly indistinguishable from malice.
This is a very common mistake and I have seen this plenty of times made by beginners.
IInterface** ppItf;
pUnk->QueryInterface(ppItf);
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
When using the CMapXXX classes, you are supposed to pass in the address to a 'type' to receive the value at the key. It is even more interesting if you merely declare a pointer as a stack variable and pass that instead... In header file...
typedef CTypedPtrMap< CMapWordToPtr, WORD, WORD* > HandleMap;
class whatever { ... HandleMap m_HandleMap ... };
Then you perform a lookup like this, for example:BOOL WhatEver::DoesKeyExist(WORD wKey) { WORD *pDummy; :wtf: if( !m_HandleMap.Lookup(wKey, pDummy) ){ return FALSE; } return TRUE; }
Assuming it DOES find the key, where does the value stored at the key go ? What does pDummy actually point to ?Any sufficiently gross incompetence is nearly indistinguishable from malice.
In debug builds, local variables are initialized to CC, so the pointer will point to 0xCCCCCCCC and the app will crash when it tries to write to that address. In release builds, there's no predicting what value it'll get since it will pick up whatever data was at that point on the stack.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ