summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2008-11-19 14:32:05 +0000
committerSimon Marlow <marlowsd@gmail.com>2008-11-19 14:32:05 +0000
commitdb12b8eaab53788cf29c589beca82511e48249e4 (patch)
treedf12e8893487008838ab30547d55deb68ddf3bc8
parent65914a2cb71caf01655b16a75b283871e2482041 (diff)
downloadhaskell-db12b8eaab53788cf29c589beca82511e48249e4.tar.gz
Fix some unsigned comparisions that should be signed
Fixes crashes when using reclaimSpark() (not used currently, but may be in the future).
-rw-r--r--rts/Sparks.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/rts/Sparks.c b/rts/Sparks.c
index 571529afbb..9e4492ac19 100644
--- a/rts/Sparks.c
+++ b/rts/Sparks.c
@@ -208,7 +208,9 @@ steal(SparkPool *deque)
b = deque->bottom;
t = deque->top;
- if (b - t <= 0 ) {
+ // NB. b and t are unsigned; we need a signed value for the test
+ // below.
+ if ((long)b - (long)t <= 0 ) {
return NULL; /* already looks empty, abort */
}
@@ -259,7 +261,7 @@ looksEmpty(SparkPool* deque)
StgWord t = deque->top;
StgWord b = deque->bottom;
/* try to prefer false negatives by reading top first */
- return (b - t <= 0);
+ return ((long)b - (long)t <= 0);
/* => array is *never* completely filled, always 1 place free! */
}
@@ -304,7 +306,10 @@ pushBottom (SparkPool* deque, StgClosurePtr elem)
This is why we do not just call empty(deque) here.
*/
t = deque->topBound;
- if ( b - t >= sz ) { /* nota bene: sz == deque->size - 1, thus ">=" */
+ if ( (StgInt)b - (StgInt)t >= (StgInt)sz ) {
+ /* NB. 1. sz == deque->size - 1, thus ">="
+ 2. signed comparison, it is possible that t > b
+ */
/* could be full, check the real top value in this case */
t = deque->top;
deque->topBound = t;