restored else branch for other ports
[fw/sdcc] / support / regression / tests / bug-524691.c
index 542cedcfbbb1e83d57474d8d84564eca2e5f96cf..dfc2f0db1f714e639ce3c6f88984babc43d6a473 100644 (file)
@@ -19,6 +19,7 @@ static HeapEntryState *_getHeapEntryState(void *p, HeapEntryState *pStates, UINT
       int iDiff;
 
       uMiddle = (uLeft + uRight)/2;
+      /* A divide by zero is added just before iDiff is assigned */
       iDiff = pStates[uMiddle].pBase - p;
 
       if (iDiff > 0)
@@ -37,3 +38,17 @@ static HeapEntryState *_getHeapEntryState(void *p, HeapEntryState *pStates, UINT
 
   return NULL;
 }
+
+void
+testDivByZero(void)
+{
+  HeapEntryState aStates[] = {
+    { (void xdata *)1, 0 }
+  };
+  void *p = (void xdata *)0x1234;
+
+  ASSERT(_getHeapEntryState(p, aStates, 1) == NULL);
+
+  aStates[0].pBase = p;
+  ASSERT(_getHeapEntryState(p, aStates, 1) == aStates + 0);
+}