Fix a long standing bug within dvmHeapSourceGetObjectBitmaps. All
callers of this function assign the return value to an unsigned value
even though this function returns -1 in the error case. This causes
the error checks to succeed in cases where it should otherwise fail.
Rather than return -1 on error, I have elected to return 0 instead
which just happens to be compatible with all current uses.
diff --git a/vm/alloc/HeapSource.c b/vm/alloc/HeapSource.c
index 4407941..384ec78 100644
--- a/vm/alloc/HeapSource.c
+++ b/vm/alloc/HeapSource.c
@@ -591,16 +591,17 @@
/*
* Writes shallow copies of the currently-used bitmaps into outBitmaps,
- * returning the number of bitmaps written. Returns <0 if the array
- * was not long enough.
+ * returning the number of bitmaps written. Returns 0 if the array was
+ * not long enough or if there are no heaps, either of which is an error.
*/
-ssize_t
+size_t
dvmHeapSourceGetObjectBitmaps(HeapBitmap outBitmaps[], size_t maxBitmaps)
{
HeapSource *hs = gHs;
HS_BOILERPLATE();
+ assert(hs->numHeaps != 0);
if (maxBitmaps >= hs->numHeaps) {
size_t i;
@@ -609,7 +610,7 @@
}
return i;
}
- return -1;
+ return 0;
}
/*
diff --git a/vm/alloc/HeapSource.h b/vm/alloc/HeapSource.h
index fdaf119..3909123 100644
--- a/vm/alloc/HeapSource.h
+++ b/vm/alloc/HeapSource.h
@@ -56,10 +56,10 @@
/*
* Writes shallow copies of the currently-used bitmaps into outBitmaps,
- * returning the number of bitmaps written. Returns <0 if the array
- * was not long enough.
+ * returning the number of bitmaps written. Returns 0 if the array was
+ * not long enough or if there are no heaps, either of which is an error.
*/
-ssize_t dvmHeapSourceGetObjectBitmaps(HeapBitmap outBitmaps[],
+size_t dvmHeapSourceGetObjectBitmaps(HeapBitmap outBitmaps[],
size_t maxBitmaps);
/*
diff --git a/vm/alloc/MarkSweep.c b/vm/alloc/MarkSweep.c
index 6f41f88..78286cf 100644
--- a/vm/alloc/MarkSweep.c
+++ b/vm/alloc/MarkSweep.c
@@ -146,7 +146,7 @@
numBitmaps = dvmHeapSourceGetObjectBitmaps(objectBitmaps,
HEAP_SOURCE_MAX_HEAP_COUNT);
- if (numBitmaps <= 0) {
+ if (numBitmaps == 0) {
return false;
}