summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 18:39:59 +0000
committercraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 18:39:59 +0000
commit002c9bbb960f20bbb088fc716e3438d673750729 (patch)
tree69f3d6bca72f014d0c9feb72feef35d2c45439e1
parent17d3c2d593b73244f1fea106e6f4287dd798c017 (diff)
downloadchromium_src-002c9bbb960f20bbb088fc716e3438d673750729.zip
chromium_src-002c9bbb960f20bbb088fc716e3438d673750729.tar.gz
chromium_src-002c9bbb960f20bbb088fc716e3438d673750729.tar.bz2
Fix some strict aliasing errors from r31773 caught with gcc 4.4.
I've chosen to use a union here instead of restoring the original memcpy code. Errors were as follows: cc1plus: warnings being treated as errors chrome/browser/safe_browsing/safe_browsing_database_bloom.cc: In member function ‘virtual bool SafeBrowsingDatabaseBloom::ContainsUrl(const GURL&, std::string*, std::vector<int, std::allocator<int> >*, std::vector<SBFullHashResult, std::allocator<SBFullHashResult> >*, base::Time)’: chrome/browser/safe_browsing/safe_browsing_database_bloom.cc:274: error: dereferencing pointer ‘full_hash.207’ does break strict-aliasing rules chrome/browser/safe_browsing/safe_browsing_database_bloom.cc:274: note: initialized from here chrome/browser/safe_browsing/safe_browsing_database_bloom.cc: In member function ‘void SafeBrowsingDatabaseBloom::InsertSub(int, SBPrefix, SBEntry*)’: chrome/browser/safe_browsing/safe_browsing_database_bloom.cc:478: error: dereferencing pointer ‘full_hash.258’ does break strict-aliasing rules chrome/browser/safe_browsing/safe_browsing_database_bloom.cc:478: note: initialized from here chrome/browser/safe_browsing/safe_browsing_database_bloom.cc: In member function ‘void SafeBrowsingDatabaseBloom::InsertAdd(SBPrefix, SBEntry*)’: chrome/browser/safe_browsing/safe_browsing_database_bloom.cc:402: error: dereferencing pointer ‘full_hash.237’ does break strict-aliasing rules chrome/browser/safe_browsing/safe_browsing_database_bloom.cc:402: note: initialized from here make: *** [out/Release/obj.target/browser/chrome/browser/safe_browsing/safe_browsing_database_bloom.o] Error 1 Review URL: http://codereview.chromium.org/389021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31798 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.cc10
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.h3
2 files changed, 7 insertions, 6 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
index 46fa2b7..1f4d943 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
@@ -271,7 +271,7 @@ bool SafeBrowsingDatabaseBloom::ContainsUrl(
// and then fall back to the full hash if there's a hit.
base::SHA256HashString(hosts[i] + paths[j], &full_hash,
sizeof(SBFullHash));
- SBPrefix prefix = *reinterpret_cast<SBPrefix*>(&full_hash);
+ SBPrefix prefix = full_hash.prefix;
if (bloom_filter_->Exists(prefix))
prefix_hits->push_back(prefix);
}
@@ -399,7 +399,7 @@ void SafeBrowsingDatabaseBloom::InsertAdd(SBPrefix host, SBEntry* entry) {
base::Time receive_time = base::Time::Now();
for (int i = 0; i < entry->prefix_count(); ++i) {
SBFullHash full_hash = entry->FullHashAt(i);
- SBPrefix prefix = *reinterpret_cast<SBPrefix*>(&full_hash);
+ SBPrefix prefix = full_hash.prefix;
InsertAddPrefix(prefix, encoded);
InsertAddFullHash(prefix, encoded, receive_time, full_hash);
}
@@ -475,7 +475,7 @@ void SafeBrowsingDatabaseBloom::InsertSub(
if (entry->type() == SBEntry::SUB_FULL_HASH) {
for (int i = 0; i < entry->prefix_count(); ++i) {
SBFullHash full_hash = entry->FullHashAt(i);
- SBPrefix prefix = *reinterpret_cast<SBPrefix*>(&full_hash);
+ SBPrefix prefix = full_hash.prefix;
encoded_add = EncodeChunkId(entry->ChunkIdAtPrefix(i), entry->list_id());
InsertSubPrefix(prefix, encoded, encoded_add);
InsertSubFullHash(prefix, encoded, encoded_add, full_hash, false);
@@ -1069,7 +1069,7 @@ void SafeBrowsingDatabaseBloom::WriteFullHashList(const HashList& hash_list,
HashList::const_iterator lit = hash_list.begin();
for (; lit != hash_list.end(); ++lit) {
const HashCacheEntry& entry = *lit;
- SBPrefix prefix = *reinterpret_cast<const SBPrefix*>(&entry.full_hash);
+ SBPrefix prefix = entry.full_hash.prefix;
if (is_add) {
if (add_del_cache_.find(entry.add_chunk_id) == add_del_cache_.end()) {
InsertAddFullHash(prefix, entry.add_chunk_id,
@@ -1368,7 +1368,7 @@ void SafeBrowsingDatabaseBloom::CacheHashResults(
const Time now = Time::Now();
for (std::vector<SBFullHashResult>::const_iterator it = full_hits.begin();
it != full_hits.end(); ++it) {
- SBPrefix prefix = *reinterpret_cast<const SBPrefix*>(&it->hash);
+ SBPrefix prefix = it->hash.prefix;
HashList& entries = (*hash_cache_)[prefix];
HashCacheEntry entry;
entry.received = now;
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.h b/chrome/browser/safe_browsing/safe_browsing_util.h
index a184ca6..8c2d60b 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.h
+++ b/chrome/browser/safe_browsing/safe_browsing_util.h
@@ -41,8 +41,9 @@ typedef struct {
typedef int SBPrefix;
// A full hash.
-typedef struct {
+typedef union {
char full_hash[32];
+ SBPrefix prefix;
} SBFullHash;
inline bool operator==(const SBFullHash& rhash, const SBFullHash& lhash) {