Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Unified Diff: base/metrics/field_trial.cc

Issue 10088001: Fixing issues with alignment, undefined behaviour and endianness in the FieldTrial::HashName functi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/sys_byteorder.h » ('j') | base/sys_byteorder.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.cc
diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc
index 28886f00ee7ea1ca42c2eebd23a2399ad55a0a22..0e84e805e1bf77758b3ddb98bee0ad48b28b7598 100644
--- a/base/metrics/field_trial.cc
+++ b/base/metrics/field_trial.cc
@@ -10,6 +10,7 @@
#include "base/sha1.h"
#include "base/stringprintf.h"
#include "base/string_util.h"
+#include "base/sys_byteorder.h"
#include "base/utf_string_conversions.h"
namespace base {
@@ -212,13 +213,14 @@ uint32 FieldTrial::HashName(const std::string& name) {
sha1_hash);
COMPILE_ASSERT(sizeof(uint32) < sizeof(sha1_hash), need_more_data);
- uint32* bits = reinterpret_cast<uint32*>(&sha1_hash[0]);
+ uint32 bits;
+ memcpy(&bits, sha1_hash, sizeof(bits));
// We only DCHECK, since this should not happen because the registration
// of the experiment on the server should have already warn the developer.
// If this ever happen, we'll ignore this experiment/group when reporting.
- DCHECK(*bits != kReservedHashValue);
- return *bits;
+ DCHECK(bits != kReservedHashValue);
+ return base::ByteSwapToLE32(bits);
}
//------------------------------------------------------------------------------
« no previous file with comments | « no previous file | base/sys_byteorder.h » ('j') | base/sys_byteorder.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698