OSDN Git Service

Fix undefined behavior in hash calculation.
authorDan Albert <danalbert@google.com>
Thu, 16 Apr 2015 18:54:24 +0000 (11:54 -0700)
committerDan Albert <danalbert@google.com>
Fri, 17 Apr 2015 17:23:55 +0000 (10:23 -0700)
dex_register might be >= the width of the map hash. Shifting by that
value would be undefined behavior. Constrain the value to within the
valid range.

Change-Id: I9037c5c7ec554850ba3385585aca96fde1d50387

compiler/optimizing/stack_map_stream.h

index a73c8d7..9a9e068 100644 (file)
@@ -386,7 +386,8 @@ class StackMapStream : public ValueObject {
       }
 
       entry.live_dex_registers_mask->SetBit(dex_register);
-      entry.dex_register_map_hash += (1 << dex_register);
+      entry.dex_register_map_hash +=
+        (1 << (dex_register % (sizeof(entry.dex_register_map_hash) * kBitsPerByte)));
       entry.dex_register_map_hash += static_cast<uint32_t>(value);
       entry.dex_register_map_hash += static_cast<uint32_t>(kind);
       stack_maps_.Put(stack_maps_.Size() - 1, entry);