From 7edb08f083dbe1408285a083e4132673b6e1d7be Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 21 Mar 2007 18:20:24 +0000 Subject: Fixed another random bug in the string compare for raw strings. --- src/hash.cpp | 4 +-- src/tests/hashtest2.cpp | 70 +++++-------------------------------------------- 2 files changed, 8 insertions(+), 66 deletions(-) diff --git a/src/hash.cpp b/src/hash.cpp index 004d6dd..c52e6b1 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -45,7 +45,7 @@ template<> bool __cmpHashKeys( const char * const &a, const char * return true; for(int j=0; a[j] == b[j]; j++ ) - if( *a == '\0' ) + if( a[j] == '\0' ) return true; return false; @@ -74,7 +74,7 @@ template<> bool __cmpHashKeys( char * const &a, char * const &b ) return true; for(int j=0; a[j] == b[j]; j++ ) - if( *a == '\0' ) + if( a[j] == '\0' ) return true; return false; diff --git a/src/tests/hashtest2.cpp b/src/tests/hashtest2.cpp index 9ac75d5..74700fd 100644 --- a/src/tests/hashtest2.cpp +++ b/src/tests/hashtest2.cpp @@ -1,72 +1,14 @@ #include "hash.h" #include -typedef struct CC -{ - const char *sKey; - const char *sData; -} CC; - -char *c(const char *s) -{ - int l = strlen(s); - char *o = new char[l+1]; - o[l] = '\0'; - memcpy(o, s, l); - - return o; -} - -CC *mkCC(const char *k, const char *d) -{ - CC *o = new CC; - o->sKey = c(k); - o->sData = c(d); - return o; -} - -void klCC(CC *c) -{ - delete[] c->sKey; - delete[] c->sData; - delete c; -} - -typedef Hash CCHash; - int main() { - char buf1[200]; - char buf2[200]; - CCHash h; - CC *tmp; - - for(int i=0;i<10;i++) - { - sprintf(buf1, "key_%d", i); - sprintf(buf2, "data_%d", i); - tmp = mkCC(buf1, buf2); - h[tmp->sKey] = tmp; - } - - for(int i=0;i<12;i++) - { - sprintf(buf1, "key_%d", i); - if(h.has(buf1)) - { - tmp = h[buf1]; - printf("GOT %s = %s\n", tmp->sKey, tmp->sData); - } - else - printf("%s is not in the table.\n", buf1); - } - - CCHash::iterator it = h.begin(); - for(;it!=h.end();it++) - { - tmp = (*it).second; - klCC(tmp); - } + char *a, *b; + a = new char[10]; + b = new char[10]; + strcpy( a, "Hey there"); + strcpy( b, "Hey there"); + printf("Same: %s\n", __cmpHashKeys( a, b )?"yes":"no"); return 0; } -- cgit v1.2.3