1 /* Division by powers of two.
5 typedef unsigned int UINT;
7 typedef struct _HeapEntryState
13 static HeapEntryState *_getHeapEntryState(void *p, HeapEntryState *pStates, UINT nStateEntries)
15 int uLeft = -1, uRight = nStateEntries, uMiddle;
17 while (uRight - uLeft > 1)
21 uMiddle = (uLeft + uRight)/2;
22 /* A divide by zero is added just before iDiff is assigned */
23 iDiff = pStates[uMiddle].pBase - p;
35 return pStates + uMiddle;
45 HeapEntryState aStates[] = {
46 { (void xdata *)1, 0 }
48 void *p = (void xdata *)0x1234;
50 ASSERT(_getHeapEntryState(p, aStates, 1) == NULL);
53 ASSERT(_getHeapEntryState(p, aStates, 1) == aStates + 0);