ucrmk / memcacheclient

Automatically exported from code.google.com/p/memcacheclient
0 stars 0 forks source link

MemCacheClientTest: MemCacheClient.cpp:438: long unsigned int MemCacheClient::CreateKeyHash(const char*): Assertion `sizeof(output.as_long) == 20' failed. #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. compile the project on x64 linux os
2. run MemCacheClientTest

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
http://code.jellycan.com/files/memcacheclient-2.0.zip

Please provide any additional information below.
on x64 linux OS : sizeof(long) = 64,, this is the problem is.

Original issue reported on code.google.com by ziec...@gmail.com on 24 Jun 2012 at 4:34

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Index: MemCacheClient.cpp
===================================================================
--- MemCacheClient.cpp  (revision 24)
+++ MemCacheClient.cpp  (working copy)
@@ -355,7 +355,7 @@
         const ConsistentHash & server = mServerHash[n];
         mTrace.Trace(CLDEBUG, "%2u: %08lx = %s (services: 0x%x, entry: %d)", 
             n, server.mHash, server.mServer->GetAddress(), server.mServices, server.mEntry);
-        snprintf(buf, sizeof(buf), "%s>%d>%x>%lx>", 
server.mServer->GetAddress(), 
+        snprintf(buf, sizeof(buf), "%s>%d>%x>%x>", 
server.mServer->GetAddress(), 
             server.mEntry, server.mServices, server.mHash);
         verify += buf;
     }
@@ -420,16 +420,16 @@
     mRetryMs = aRetryMs;
 }

-unsigned long 
+MemCacheClient::uint32_t
 MemCacheClient::CreateKeyHash(
     const char * aKey
     )
 {
-    const size_t LONG_COUNT = SHA_DIGEST_LENGTH / sizeof(unsigned long);
+    const size_t LONG_COUNT = SHA_DIGEST_LENGTH / sizeof(uint32_t);

     union {
         unsigned char as_char[SHA_DIGEST_LENGTH];
-        unsigned long as_long[LONG_COUNT];
+        uint32_t as_long[LONG_COUNT];
     } output;

     CR_ASSERT(sizeof(output.as_char) == SHA_DIGEST_LENGTH);
Index: MemCacheClient.h
===================================================================
--- MemCacheClient.h    (revision 24)
+++ MemCacheClient.h    (working copy)
@@ -142,8 +142,10 @@
     typedef std::string         string_t;   //!< Abstract the string class for internal use
 #ifdef WIN32
     typedef unsigned __int64    uint64_t;   //!< 64-bit unsigned type
+    typedef unsigned __int32    uint32_t;   //!< 32-bit unsigned type
 #else
     typedef unsigned long long  uint64_t;   //!< 64-bit unsigned type
+    typedef ::uint32_t          uint32_t;   //!< 32-bit unsigned type
 #endif

     /*! @brief Input and output structure for most requests to the server */
@@ -560,7 +562,7 @@
         changes to the server list doesn't invalidate all cached data.
      */
     struct ConsistentHash { 
-        unsigned long   mHash;      //!< hash value
+        uint32_t        mHash;      //!< hash value
         Server *        mServer;    //!< server implementation
         unsigned        mServices;  //!< services this server provides
         int             mEntry;     //!< distinguish same hash and server
@@ -592,7 +594,7 @@
     std::vector<ConsistentHash> mServerHash;

     /*! create a hash value from the key */
-    unsigned long CreateKeyHash(const char * aKey);
+    uint32_t CreateKeyHash(const char * aKey);

     /*! find which server will be used to handle the key */
     Server * FindServer(const string_t & aKey, unsigned aService);

Original comment by ziec...@gmail.com on 24 Jun 2012 at 5:28