2009-11-19 18:51:37 UTC
to be related to the allocation of member variables on the heap. I am
reporting the problem here in vc.debugger since there is an associated
Watch window glitch that appears to be related.
In the code snippet below, creating a new CTestObject2 results in a
heap error at certain heap addresses. I believe this is due to the
bool's in CTestObject2 being misaligned in some cases under the
The interesting thing here is that a sizeof(*this) in the CTestObject2
constructor will return 40 bytes, but if I do sizeof(*this) from the
watch window while stopped there, I get 34 bytes, which is what the
size would be with /Zp1 alignment. While this could be a Watch window
glitch, the behavior only appears when the heap error occurs.
If I do not call _heapchk, calls to set the member variables appear to
write different memory locations than calls to read the member
If I replace the bool's with BOOL's, the size is 40 bytes in both
cases and no heap exception occurs.
Note that I can only get this to occur in my production application.
Smaller test cases with the same compiler options are not reproducing
the behavior, even when the heap is allocated to match the original
addresses. In the test apps, sizeof(*this) always returns 40.
class CTestList : public CTypedPtrList<CPtrList,void*>
ASSERT(_heapchk() == _HEAPOK);
CTestObject2 size=40 loc=025E3ED8 to 025E4518
.m_bool_1 size=1 loc=025E3ED8 to 025E3ED8
.m_ptr_1 size=4 loc=025E3EDC to 025E3EDF
.m_bool_2 size=1 loc=025E3EE0 to 025E3EE0
.m_list_1 size=28 loc=025E3EE4 to 025E3EFF
HEAP[TradingSolutions.exe]: Heap block at 025E3EB0 modified at
025E3EFE past requested size of 46