From: michaelh Date: Sat, 2 Mar 2002 05:44:18 +0000 (+0000) Subject: Added X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=5309904f7767d1c3e543bca85bd826f5174d3544;p=fw%2Fsdcc Added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1969 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/support/regression/tests/bug-524691.c b/support/regression/tests/bug-524691.c new file mode 100644 index 00000000..542cedcf --- /dev/null +++ b/support/regression/tests/bug-524691.c @@ -0,0 +1,39 @@ +/* Division by powers of two. + */ +#include + +typedef unsigned int UINT; + +typedef struct _HeapEntryState +{ + void *pBase; + UINT uFlags; +} HeapEntryState; + +static HeapEntryState *_getHeapEntryState(void *p, HeapEntryState *pStates, UINT nStateEntries) +{ + int uLeft = -1, uRight = nStateEntries, uMiddle; + + while (uRight - uLeft > 1) + { + int iDiff; + + uMiddle = (uLeft + uRight)/2; + iDiff = pStates[uMiddle].pBase - p; + + if (iDiff > 0) + { + uRight = uMiddle; + } + else if (iDiff < 0) + { + uLeft = uMiddle; + } + else + { + return pStates + uMiddle; + } + } + + return NULL; +}