From b797d7a7c4481c20b26ecf6ce7ef77e4782534bb Mon Sep 17 00:00:00 2001 From: David Date: Wed, 30 Aug 2006 00:34:28 +0000 Subject: david - creepy forgot to commit hashtable stuff... also fixed something in md5... it was using uninitialized data... --- src/hashfunctionstring.cpp | 17 +++++++++++ src/hashtable.cpp | 72 +++++++++++++++++++++++++--------------------- src/md5.cpp | 2 +- 3 files changed, 58 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/hashfunctionstring.cpp b/src/hashfunctionstring.cpp index 6ce7bb3..bd14643 100644 --- a/src/hashfunctionstring.cpp +++ b/src/hashfunctionstring.cpp @@ -1,4 +1,7 @@ #include "hashfunctionstring.h" +#ifndef NULL +#define NULL ((void *) 0) +#endif HashFunctionString::HashFunctionString() { @@ -10,6 +13,11 @@ HashFunctionString::~HashFunctionString() unsigned long int HashFunctionString::hash( const void *id ) { + if (id == NULL) + { + return 0; + } + unsigned long int nPos = 0; for( const char *s = (const char *)id; *s; s++ ) { @@ -20,6 +28,15 @@ unsigned long int HashFunctionString::hash( const void *id ) bool HashFunctionString::cmpIDs( const void *id1, const void *id2 ) { + if (id1 == NULL || id2 == NULL) + { + return false; + } + if (id1 == id2) + { + return true; + } + const char *str1 = (const char *)id1; const char *str2 = (const char *)id2; diff --git a/src/hashtable.cpp b/src/hashtable.cpp index ea13236..37c3149 100644 --- a/src/hashtable.cpp +++ b/src/hashtable.cpp @@ -203,16 +203,18 @@ const void *HashTable::get( const void *id, unsigned long int nSkip ) for( unsigned long int j=0; j < 32; nPos = (nPos+(1<cmpIDs( id, aTable[nPos].id ) && - aTable[nPos].bDeleted == false ) + if( aTable[nPos].bDeleted == false ) { - if( nSkip == 0 ) - { - return aTable[nPos].data; - } - else + if( hFunc->cmpIDs( id, aTable[nPos].id ) ) { - nSkip--; + if( nSkip == 0 ) + { + return aTable[nPos].data; + } + else + { + nSkip--; + } } } } @@ -223,16 +225,18 @@ const void *HashTable::get( const void *id, unsigned long int nSkip ) for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) { if( !isFilled( nPos ) ) return NULL; - if( hFunc->cmpIDs( id, aTable[nPos].id ) && - aTable[nPos].bDeleted == false ) + if( aTable[nPos].bDeleted == false ) { - if( nSkip == 0 ) + if( hFunc->cmpIDs( id, aTable[nPos].id ) ) { - return aTable[nPos].data; - } - else - { - nSkip--; + if( nSkip == 0 ) + { + return aTable[nPos].data; + } + else + { + nSkip--; + } } } } @@ -248,16 +252,18 @@ const void *HashTable::getKey( const void *id, unsigned long int nSkip ) for( unsigned long int j=0; j < 32; nPos = (nPos+(1<cmpIDs( id, aTable[nPos].id ) && - aTable[nPos].bDeleted == false ) + if( aTable[nPos].bDeleted == false ) { - if( nSkip == 0 ) - { - return aTable[nPos].id; - } - else + if( hFunc->cmpIDs( id, aTable[nPos].id ) ) { - nSkip--; + if( nSkip == 0 ) + { + return aTable[nPos].id; + } + else + { + nSkip--; + } } } } @@ -268,16 +274,18 @@ const void *HashTable::getKey( const void *id, unsigned long int nSkip ) for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) { if( !isFilled( nPos ) ) return NULL; - if( hFunc->cmpIDs( id, aTable[nPos].id ) && - aTable[nPos].bDeleted == false ) + if( aTable[nPos].bDeleted == false ) { - if( nSkip == 0 ) + if( hFunc->cmpIDs( id, aTable[nPos].id ) ) { - return aTable[nPos].id; - } - else - { - nSkip--; + if( nSkip == 0 ) + { + return aTable[nPos].id; + } + else + { + nSkip--; + } } } } diff --git a/src/md5.cpp b/src/md5.cpp index ed7e4ac..c0cacdd 100644 --- a/src/md5.cpp +++ b/src/md5.cpp @@ -143,7 +143,7 @@ long *md5::c2l( const char *str, long len, long *nNewLen ) long mlen = OBLOC( len8 ); long flen = (((mlen/16)+((mlen%16)?(1):(0))))*16; long *aBin = new long[flen]; - memset( aBin, 0, flen ); + memset( aBin, 0, flen*4 ); for( long i = 0; i < len8; i+=8 ) { -- cgit v1.2.3