]> andersk Git - splint.git/blobdiff - src/genericTable.c
Fixes for win32
[splint.git] / src / genericTable.c
index bdc07979f033832eb5d981ea5fc6debe381f5246..75067f628ef724a2474bd358fdfa0946abbc72e8 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -17,8 +17,8 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on splint: splint@cs.virginia.edu
-** To report a bug: splint-bug@cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
 ** For more information: http://www.splint.org
 */
 /*
@@ -53,6 +53,15 @@ ghentry_create (/*@keep@*/ cstring key, /*@keep@*/ void *val)
   return (h);
 }
 
+static void
+ghentry_free (/*@only@*/ ghentry ghe)
+{
+  cstring_free (ghe->key);
+  /* can't free val contents */
+  sfree (ghe->val);
+  sfree (ghe);
+}
+
 static bool
 ghbucket_isEmpty (ghbucket h)
 {
@@ -95,7 +104,7 @@ static ghbucket ghbucket_single (/*@keep@*/ ghentry e)
   h->size = 1;
   h->nspace = GHBUCKET_BASESIZE - 1;
   h->entries = (ghentry *) dmalloc (GHBUCKET_BASESIZE * sizeof (*h->entries));
-  /*@i23@*/ h->entries[0] = e;
+  h->entries[0] = e;
   
   return (h);
 }
@@ -116,9 +125,10 @@ ghbucket_grow (/*@notnull@*/ ghbucket h)
       newentries[i] = h->entries[i]; 
     }
   
-  /*@i32@*/ sfree (h->entries);
+  sfree (h->entries);
   h->entries = newentries; 
-/*@i32@*/ }
+  /*@-compmempass@*/
+} /*@=compmempass*/ /* Spurious warnings reported for h->entries */ 
 
 static /*@null@*/ /*@exposed@*/ void *ghbucket_lookup (ghbucket p_h, cstring p_key);
 
@@ -130,20 +140,23 @@ static /*@null@*/ /*@exposed@*/ void *ghbucket_lookup (ghbucket p_h, cstring p_k
 static void
 ghbucket_add (/*@notnull@*/ ghbucket h, /*@only@*/ ghentry e)
 {
-    void *exloc = ghbucket_lookup (h, e->key);
-    
-    if (exloc != NULL) {
-      llassert (FALSE);
-    }
-
-    if (h->nspace == 0) {
-       ghbucket_grow (h);
-    }
-    
-    h->entries[h->size] = e;
-    h->size++;
-    h->nspace--;
-/*@i23@*/ }
+  void *exloc = ghbucket_lookup (h, e->key);
+  
+  if (exloc != NULL) {
+    llcontbug (message ("ghbucket_add: adding duplicate entry: %s",
+                       e->key));
+    ghentry_free (e);
+    return;
+  }
+  
+  if (h->nspace == 0) {
+    ghbucket_grow (h);
+  }
+  
+  h->entries[h->size] = e;
+  h->size++;
+  h->nspace--;
+}
 
 static int
 ghbucket_ncollisions (ghbucket h)
@@ -178,7 +191,14 @@ void ghbucket_free (/*@only@*/ ghbucket h)
 {
   if (!ghbucket_isNull (h))
     {
-      /*@i32@*/ sfree (h->entries);
+      int i;
+
+      for (i = 0; i < h->size; i++)  
+       {
+         ghentry_free (h->entries[i]);
+       }
+
+      sfree (h->entries);
       sfree (h);
     }
 }
@@ -323,7 +343,7 @@ genericTable_stats (genericTable h)
 }
 
 static void
-genericTable_addEntry (/*@notnull@*/ genericTable h, /*@keep@*/ ghentry e)
+genericTable_addEntry (/*@notnull@*/ genericTable h, /*@only@*/ ghentry e)
 {
   unsigned int hindex = genericTable_hashValue (h, e->key);
   /*
@@ -340,8 +360,8 @@ genericTable_addEntry (/*@notnull@*/ genericTable h, /*@keep@*/ ghentry e)
     }
   else
     {
-      /*@i23@*/ ghbucket_add (h->buckets[hindex], e);
-      /*@i23@*/ }
+      ghbucket_add (h->buckets[hindex], e);
+    }
 }
 
 void
@@ -407,13 +427,13 @@ genericTable_insert (genericTable h, cstring key, void *value)
   
   if (ghbucket_isNull (hb))
       {
-         /*@i23@*/ h->buckets[hindex] = ghbucket_single (e);
+       h->buckets[hindex] = ghbucket_single (e);
       }
   else
       {
-         ghbucket_add (hb, e);
-         /*@i23@*/ }
-/*@i23@*/ }
+       ghbucket_add (hb, e);
+      }
+}
 
 /*@null@*/ /*@exposed@*/ void *
 genericTable_lookup (genericTable h, cstring key)
This page took 0.039345 seconds and 4 git commands to generate.