AI 143506: Fix swap issue affecting big-endian machines.
Reported on android-porting mailing list (by "Anand Android").
Also renamed a local that shadowed an earlier local.
Automated import of CL 143506
diff --git a/libdex/DexSwapVerify.c b/libdex/DexSwapVerify.c
index a7dd396..bc6f51f 100644
--- a/libdex/DexSwapVerify.c
+++ b/libdex/DexSwapVerify.c
@@ -362,12 +362,15 @@
static bool swapMap(CheckState* state, DexMapList* pMap)
{
DexMapItem* item = pMap->list;
- u4 count = pMap->size;
+ u4 count;
u4 dataItemCount = 0; // Total count of items in the data section.
u4 dataItemsLeft = state->pHeader->dataSize; // See use below.
u4 usedBits = 0; // Bit set: one bit per section
bool first = true;
u4 lastOffset = 0;
+
+ SWAP_FIELD4(pMap->size);
+ count = pMap->size;
CHECK_LIST_SIZE(item, count, sizeof(DexMapItem));
@@ -392,21 +395,21 @@
}
if (isDataSectionType(item->type)) {
- u4 count = item->size;
+ u4 icount = item->size;
/*
* This sanity check on the data section items ensures that
* there are no more items than the number of bytes in
* the data section.
*/
- if (count > dataItemsLeft) {
+ if (icount > dataItemsLeft) {
LOGE("Unrealistically many items in the data section: "
- "at least %d\n", dataItemCount + count);
+ "at least %d\n", dataItemCount + icount);
return false;
}
- dataItemsLeft -= count;
- dataItemCount += count;
+ dataItemsLeft -= icount;
+ dataItemCount += icount;
}
u4 bit = mapTypeToBitMask(item->type);