]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/tossim/hashtable.c
Fixed memory bug.
[tinyos-2.x.git] / tos / lib / tossim / hashtable.c
index 8a4e19ae1af70606a39175e4b93308d74e93f4df..d04262aac161d4184b187f60d79e135ebe1f93e9 100644 (file)
@@ -24,6 +24,8 @@ static const unsigned int primes[] = {
 const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
 const float max_load_factor = 0.65;
 
+#define BAD_RECORD (0xc693748)
+
 /*****************************************************************************/
 struct hashtable *
 create_hashtable(unsigned int minsize,
@@ -133,6 +135,8 @@ hashtable_count(struct hashtable *h)
 }
 
 /*****************************************************************************/
+int entered = 0;
+
 int
 hashtable_insert(struct hashtable *h, void *k, void *v)
 {
@@ -147,12 +151,30 @@ hashtable_insert(struct hashtable *h, void *k, void *v)
          * element may be ok. Next time we insert, we'll try expanding again.*/
         hashtable_expand(h);
     }
+    if (entered) {
+      struct entry* eTest = (struct entry*)BAD_RECORD;
+      if (eTest->v == (void*)0x3f800000) {
+       //printf("Insert CORRUPT\n");
+      }
+    }
     e = (struct entry *)malloc(sizeof(struct entry));
     if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
+    if (e == (void*)BAD_RECORD) {
+      entered  = 1;
+      //printf("Allocated 0x%x\n", e);
+    }
     e->h = hash(h,k);
+    if (e->h == 4101970376) {
+      int i;
+      //printf("Inserting key with suspect hashvalue:\n  ");
+      for (i = 0; i < 20; i++) {
+       //printf("%hhi ", ((char*)k)[i]);
+      }
+      //printf("\n");
+    }
     tindex = indexFor(h->tablelength,e->h);
-    if (v == (void*)0x477fed00) {
-      printf("CORRUPT\n");
+    if (v == (void*)0x3f800000) {
+      //printf("Insert post CORRUPT\n");
     }
     e->k = k;
     e->v = v;
@@ -170,15 +192,21 @@ hashtable_search(struct hashtable *h, void *k)
     hashvalue = hash(h,k);
     tindex = indexFor(h->tablelength,hashvalue);
     e = h->table[tindex];
-    if (hashvalue == 1741511095) {
-      int i = 5;
+    if (entered) {
+      struct entry* eTest = (struct entry*)BAD_RECORD;
+      if (eTest->v == (void*)0x3f800000) {
+       //printf("Search CORRUPT\n");
+      }
     }
     while (NULL != e)
     {
         /* Check hash value to short circuit heavier comparison */
       if ((hashvalue == e->h) && (h->eqfn(k, e->k))) {
-       if ((int)e->v == 0x477fed00) {
-         printf("ALARM\n");
+       if (hashvalue == 4101970376) {
+         //printf("Retreiving key with suspect hhashvalue: 0x%x -> 0x%x\n", e, e->v);
+       }
+       if ((int)e->v == 0x3f800000) {
+         //printf("ALARM: 0x%x has 0x%x\n", e, e->v);
        }
        return e->v;
       }