On Tue Jul 25 12:12:10 2023 +0000, Rémi Bernon wrote:
if (flags & HEAP_FREE_CHECKING_ENABLED) { UINT *p32, tmp = 0; size = 4 + 3; p = pHeapAlloc( GetProcessHeap(), 0, size ); ok( !!p, "HeapAlloc failed\n" ); p32 = (UINT *)p; ok( p32[0] == 0xbaadf00d, "got %#x\n", p32[0] ); memcpy( &tmp, p + size - 3, 3 ); ok( tmp != 0xadf00d, "got %#x\n", tmp ); memset( p, 0xcc, size ); size += 2 * 4; p = pHeapReAlloc( GetProcessHeap(), 0, p, size ); ok( !!p, "HeapReAlloc failed\n" ); p32 = (UINT *)p; ok( p32[0] == 0xcccccccc, "got %#x\n", p32[0] ); ok( p32[1] << 8 == 0xcccccc00, "got %#x\n", p32[1] ); if (flags & HEAP_TAIL_CHECKING_ENABLED) ok( p32[1] >> 24 == 0xab, "got %#x\n", p32[1] ); ok( p32[2] == 0xbaadf00d, "got %#x\n", p32[2] ); memcpy( &tmp, p + size - 3, 3 ); ok( tmp != 0xadf00d, "got %#x\n", tmp ); ret = pHeapFree( GetProcessHeap(), 0, p ); ok( ret, "failed.\n" ); }
I think this would be simpler, the loops seem unnecessary. I removed the non-inplace check with 0xba, as I don't think it is reliable and hopefully doesn't matter?
I don't think that the test with 0xba matters too much, but it also seems to me that it is reliable. That is the high byte of BLOCK_FILL_USED (0xbaadf00d), and it gets there when the new block is allocated out of place and gets filled before 39 bytes are copied from the old location, so not a leftover from previous allocation at those addresses (testing those would be indeed flaky).