Solve a strict-aliasing issue in metrics_log.cc to appease gcc 4.4 on Linux.

Review URL: http://codereview.chromium.org/126104

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18487 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 2d00123..cef0a76 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -108,10 +108,14 @@
   MD5Digest digest;
   MD5Final(&digest, &ctx);
 
-  unsigned char reverse[8];  // UMA only uses first 8 chars of hash.
-  DCHECK(arraysize(digest.a) >= arraysize(reverse));
-  for (size_t i = 0; i < arraysize(reverse); ++i)
-    reverse[i] = digest.a[arraysize(reverse) - i - 1];
+  uint64 reverse_uint64;
+  // UMA only uses first 8 chars of hash. We use the above uint64 instead
+  // of a unsigned char[8] so that we don't run into strict aliasing issues
+  // in the LOG statement below when trying to interpret reverse as a uint64.
+  unsigned char* reverse = reinterpret_cast<unsigned char *>(&reverse_uint64);
+  DCHECK(arraysize(digest.a) >= sizeof(reverse_uint64));
+  for (size_t i = 0; i < sizeof(reverse_uint64); ++i)
+    reverse[i] = digest.a[sizeof(reverse_uint64) - i - 1];
   // The following log is VERY helpful when folks add some named histogram into
   // the code, but forgot to update the descriptive list of histograms.  When
   // that happens, all we get to see (server side) is a hash of the histogram
@@ -119,7 +123,7 @@
   // being hashed to a given MD5 value by just running the version of Chromium
   // in question with --enable-logging.
   LOG(INFO) << "Metrics: Hash numeric [" << value << "]=["
-      << *reinterpret_cast<const uint64*>(&reverse[0]) << "]";
+      << reverse_uint64 << "]";
   return std::string(reinterpret_cast<char*>(digest.a), arraysize(digest.a));
 }