Added
[fw/sdcc] / support / regression / tests / bug-524691.c
1 /* Division by powers of two.
2  */
3 #include <testfwk.h>
4
5 typedef unsigned int UINT;
6
7 typedef struct _HeapEntryState
8 {
9   void *pBase;
10   UINT uFlags;
11 } HeapEntryState;
12
13 static HeapEntryState *_getHeapEntryState(void *p, HeapEntryState *pStates, UINT nStateEntries)
14 {
15   int uLeft = -1, uRight = nStateEntries, uMiddle;
16
17   while (uRight - uLeft > 1)
18     {
19       int iDiff;
20
21       uMiddle = (uLeft + uRight)/2;
22       iDiff = pStates[uMiddle].pBase - p;
23
24       if (iDiff > 0)
25         {
26           uRight = uMiddle;
27         }
28       else if (iDiff < 0)
29         {
30           uLeft = uMiddle;
31         }
32       else
33         {
34           return pStates + uMiddle;
35         }
36     }
37
38   return NULL;
39 }