WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/heap.c
// Binary search if addr belongs to one of the blocks
Binary search if addr belongs to one of the blocks
Binary search if addr belongs to one of the blocks
struct inuse_block* find_inuse_block(address_t addr, struct inuse_block* blocks, unsigned long total_blocks)
{
	unsigned long l_index = 0;
	unsigned long u_index = total_blocks;
	if (addr < blocks[0].addr || addr >= blocks[total_blocks-1].addr + blocks[total_blocks-1].size)
		return NULL;
	while (l_index < u_index)
	{
		unsigned long m_index = (l_index + u_index) / 2;
		struct inuse_block* blk = &blocks[m_index];
		if (addr < blk->addr)
			u_index = m_index;
		else if (addr >= blk->addr + blk->size)
			l_index = m_index + 1;
		else
			return blk;
	}
	return NULL;
}
struct inuse_block * find_inuse_block ( address_t addr , struct inuse_block * blocks , unsigned long total_blocks ) { unsigned long l_index = 0 ; unsigned long u_index = total_blocks ; if ( addr < blocks [ 0 ] . addr || addr >= blocks [ total_blocks - 1 ] . addr + blocks [ total_blocks - 1 ] . size ) return NULL ; while ( l_index < u_index ) { unsigned long m_index = ( l_index + u_index ) / 2 ; struct inuse_block * blk = & blocks [ m_index ] ; if ( addr < blk -> addr ) u_index = m_index ; else if ( addr >= blk -> addr + blk -> size ) l_index = m_index + 1 ; else return blk ; } return NULL ; }
Binary search if addr belongs to one of the blocks
Binary search if addr belongs to one of the blocks
// bail out for out of bound addr