OSDN Git Service

AI 143506: Fix swap issue affecting big-endian machines.
authorAndy McFadden <>
Mon, 30 Mar 2009 19:56:53 +0000 (12:56 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Mon, 30 Mar 2009 19:56:53 +0000 (12:56 -0700)
  Reported on android-porting mailing list (by "Anand Android").
  Also renamed a local that shadowed an earlier local.

Automated import of CL 143506

libdex/DexSwapVerify.c

index a7dd396..bc6f51f 100644 (file)
@@ -362,12 +362,15 @@ static bool isDataSectionType(int mapType) {
 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 @@ static bool swapMap(CheckState* state, DexMapList* pMap)
         }
 
         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);