summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 13:14:08 +0000
committercraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 13:14:08 +0000
commitbe6bf5ebfb55b6eb2ef55870e30c102a4d7fd46c (patch)
tree33ac49babc6d947018bf401546302027f9dca0da
parentc463d368e8df9d18e912d98aa83956128f28c1cf (diff)
downloadchromium_src-be6bf5ebfb55b6eb2ef55870e30c102a4d7fd46c.zip
chromium_src-be6bf5ebfb55b6eb2ef55870e30c102a4d7fd46c.tar.gz
chromium_src-be6bf5ebfb55b6eb2ef55870e30c102a4d7fd46c.tar.bz2
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
-rw-r--r--chrome/browser/metrics/metrics_log.cc14
1 files changed, 9 insertions, 5 deletions
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 @@ std::string MetricsLog::CreateHash(const std::string& value) {
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 @@ std::string MetricsLog::CreateHash(const std::string& value) {
// 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));
}