From 27d5eeac767f206b9055c6e9a330e69bf6eafa33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sat, 25 May 2019 02:25:57 +0300 Subject: [PATCH] caches: make the auxilliary classes names unique This might not be the most C++ way, but better than the previous state that misbehaved (methods from FIBBICache.cc could be linked from FIPPICache.cc, causing invalid reads and possibly memory corruption). (cherry picked from commit 6e29b1789c393715b3251b810e2038b4aaaf8ddc) --- libs/libscuff/FIBBICache.cc | 17 ++++++++--------- libs/libscuff/FIPPICache.cc | 12 ++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libs/libscuff/FIBBICache.cc b/libs/libscuff/FIBBICache.cc index 15a2f5e9..a78cc9ca 100644 --- a/libs/libscuff/FIBBICache.cc +++ b/libs/libscuff/FIBBICache.cc @@ -69,9 +69,8 @@ void ComputeFIBBIData(RWGSurface *Sa, int nea, /*--------------------------------------------------------------*/ long JenkinsHash(const char *key, size_t len) { - long hash; - unsigned int i; - for(hash = i = 0; i < len; ++i) + long hash = 0; + for(size_t i = 0; i < len; ++i) { hash += key[i]; hash += (hash << 10); @@ -95,7 +94,7 @@ typedef struct { double Data[DATALEN]; } DataStruct; typedef std::pair KDPair; -struct KeyHash +struct FIBBIKeyHash { long operator() (const KeyStruct &K) const { return HashFunction(K.Key); } @@ -111,18 +110,18 @@ typedef struct ); }; - } KeyCmp; + } FIBBIKeyCmp; #ifdef HAVE_CXX11 typedef std::unordered_map< KeyStruct, DataStruct, - KeyHash, - KeyCmp> KDMap; + FIBBIKeyHash, + FIBBIKeyCmp> KDMap; #elif defined(HAVE_TR1) typedef std::tr1::unordered_map< KeyStruct, DataStruct, - KeyHash, - KeyCmp> KDMap; + FIBBIKeyHash, + FIBBIKeyCmp> KDMap; #endif /*--------------------------------------------------------------*/ diff --git a/libs/libscuff/FIPPICache.cc b/libs/libscuff/FIPPICache.cc index 47eac1ad..4f754cab 100644 --- a/libs/libscuff/FIPPICache.cc +++ b/libs/libscuff/FIPPICache.cc @@ -66,7 +66,7 @@ typedef struct typedef std::pair KeyValuePair; -struct KeyHash +struct FIPPIKeyHash { long operator() (const KeyStruct &K) const { return HashFunction(K.Key); } }; @@ -80,18 +80,18 @@ typedef struct return true; }; - } KeyCmp; + } FIPPIKeyCmp; #ifdef HAVE_CXX11 typedef std::unordered_map< KeyStruct, QIFIPPIData *, - KeyHash, - KeyCmp> KeyValueMap; + FIPPIKeyHash, + FIPPIKeyCmp> KeyValueMap; #elif defined(HAVE_TR1) typedef std::tr1::unordered_map< KeyStruct, QIFIPPIData *, - KeyHash, - KeyCmp> KeyValueMap; + FIPPIKeyHash, + FIPPIKeyCmp> KeyValueMap; #endif /*--------------------------------------------------------------*/