struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-524691.c
bloba26a6ffd0a9f1d068abc0bb2c3c7d90c18c3084e
1 /* Division by powers of two.
2 */
3 #include <testfwk.h>
4 #include <stddef.h>
6 typedef unsigned int UINT;
8 typedef struct _HeapEntryState
10 void *pBase;
11 UINT uFlags;
12 } HeapEntryState;
14 static HeapEntryState *
15 _getHeapEntryState (void *p, HeapEntryState *pStates, UINT nStateEntries)
17 int uLeft = -1, uRight = nStateEntries, uMiddle;
19 while (uRight - uLeft > 1)
21 int iDiff;
23 uMiddle = (uLeft + uRight)/2;
24 /* A divide by zero is added just before iDiff is assigned */
25 iDiff = pStates[uMiddle].pBase - p;
27 if (iDiff > 0)
29 uRight = uMiddle;
31 else if (iDiff < 0)
33 uLeft = uMiddle;
35 else
37 return pStates + uMiddle;
41 return NULL;
44 void
45 testDivByZero (void)
47 HeapEntryState aStates[] = {
48 { (void __xdata *)1, 0 }
50 void *p = (void __xdata *)0x1234;
52 ASSERT (_getHeapEntryState (p, aStates, 1) == NULL);
54 aStates[0].pBase = p;
55 ASSERT (_getHeapEntryState (p, aStates, 1) == aStates + 0);