/*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2001 University of Virginia,
+** Splint - annotation-assisted static program checker
+** Copyright (C) 1994-2003 University of Virginia,
** Massachusetts Institute of Technology
**
** This program is free software; you can redistribute it and/or modify it
** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
** MA 02111-1307, USA.
**
-** For information on lclint: lclint-request@cs.virginia.edu
-** To report a bug: lclint-bug@cs.virginia.edu
-** For more information: http://lclint.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
*/
/*
** cstringTable.c
**
*/
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
# include "basic.h"
# include "randomNumbers.h"
cstringTable_addEntry (/*@notnull@*/ cstringTable p_h, /*@only@*/ hentry p_e)
/*@modifies p_h@*/ ;
-static /*@truenull@*/ bool hbucket_isNull (/*@null@*/ hbucket h)
+static /*@nullwhentrue@*/ bool hbucket_isNull (/*@null@*/ hbucket h)
{
return (h == hbucket_undefined);
}
-static hentry hentry_create (/*@keep@*/ cstring key, int val)
+static hentry hentry_create (/*@only@*/ cstring key, int val)
{
hentry h = (hentry) dmalloc (sizeof (*h));
h->key = key;
h->val = val;
- llassert (val != HBUCKET_DNE); /*@i523 way bogus! */
-
+ llassert (val != HBUCKET_DNE);
return (h);
}
for (i = 0; i < h->size; i++)
{
- s = message ("%q %s:%d", s, h->entries[i]->key, h->entries[i]->val);
+ s = message ("%q %s:%d", s, h->entries[i]->key, h->entries[i]->val);
}
}
h->size = 1;
h->nspace = HBUCKET_BASESIZE - 1;
h->entries = (hentry *) dmalloc (HBUCKET_BASESIZE * sizeof (*h->entries));
- h->entries[0] = e;
+ h->entries[0] = e;
return (h);
}
newentries[i] = h->entries[i];
}
- /*@i32@*/ sfree (h->entries);
+ sfree (h->entries);
h->entries = newentries;
-/*@i23@*/ }
+ /*@-compmempass@*/
+} /*@=compmempass@*/ /* Spurious warnings reported - shouldn't need this */
static int hbucket_lookup (hbucket p_h, cstring p_key);
for (i = 0; i < h->size; i++)
{
- if (cstring_equal (h->entries[i]->key, key))
+ if (cstring_equal (h->entries[i]->key, key))
{
return h->entries[i]->val;
}
{
if (!hbucket_isNull (h))
{
- /*@i32@*/ sfree (h->entries);
+ int i;
+ /* evans 2002-07-12: added this to free entries (splint warning had been suppressed) */
+ for (i = 0; i < h->size; i++)
+ {
+ hentry_free (h->entries[i]);
+ }
+
+ sfree (h->entries);
sfree (h);
}
}
void
cstringTable_free (/*@only@*/ cstringTable h)
{
- int i;
+ unsigned int i;
llassert (cstringTable_isDefined (h));
cstringTable_countCollisions (cstringTable h)
{
int nc = 0;
- int i;
+ unsigned long i;
llassert (cstringTable_isDefined (h));
for (i = 0; i < h->size; i++)
{
- nc += hbucket_ncollisions (h->buckets[i]);
+ nc += hbucket_ncollisions (h->buckets[i]);
}
return (nc);
cstringTable_countEmpty (cstringTable h)
{
int nc = 0;
- int i;
+ unsigned long i;
llassert (cstringTable_isDefined (h));
for (i = 0; i < h->size; i++)
{
- if (hbucket_isEmpty (h->buckets[i]))
+ if (hbucket_isEmpty (h->buckets[i]))
{
nc++;
}
/*@only@*/ cstringTable
-cstringTable_create (int size)
+cstringTable_create (unsigned long size)
{
- int i;
+ unsigned long i;
cstringTable h = (cstringTable) dmalloc (sizeof (*h));
h->size = size;
/*@+loopexec@*/
for (i = 0; i < size; i++)
{
- h->buckets[i] = hbucket_undefined;
+ h->buckets[i] = hbucket_undefined;
}
/*@-loopexec@*/
return h;
cstring cstringTable_unparse (cstringTable h)
{
cstring res = cstring_newEmpty ();
- int i;
+ unsigned long i;
if (cstringTable_isDefined (h))
{
for (i = 0; i < h->size; i++)
{
- hbucket hb = h->buckets[i];
+ hbucket hb = h->buckets[i];
if (hb != NULL)
{
- res = message ("%q%d. %q\n", res, i, hbucket_unparse (hb));
+ res = message ("%q%ul. %q\n", res, i, hbucket_unparse (hb));
}
}
- res = message ("%qsize: %d, collisions: %d, empty: %d",
+ res = message ("%qsize: %ul, collisions: %d, empty: %d",
res,
h->size,
cstringTable_countCollisions (h),
cstringTable_stats (cstringTable h)
{
llassert (cstringTable_isDefined (h));
- return (message ("size: %d, collisions: %d, empty: %d\n",
+ return (message ("size: %ul, collisions: %d, empty: %d\n",
h->size, cstringTable_countCollisions (h),
cstringTable_countEmpty (h)));
}
** rehashing based (loosely) on code by Steve Harrison
*/
- int i;
- int oldsize = h->size;
- int newsize = 1 + ((oldsize * 26244) / 10000); /* 26244 = 162^2 */
+ unsigned long i;
+ /* Fix provided by Thomas Mertz (int -> unsigned long), 21 Apr 2004 */
+ unsigned long oldsize = h->size;
+ unsigned long newsize = 1 + ((oldsize * 26244) / 10000); /* 26244 = 162^2 */
hbucket *oldbuckets = h->buckets;
h->size = newsize;
/*@+loopexec@*/
for (i = 0; i < newsize; i++)
{
- h->buckets[i] = hbucket_undefined;
+ h->buckets[i] = hbucket_undefined;
}
/*@=loopexec@*/
for (i = 0; i < oldsize; i++)
{
- hbucket bucket = oldbuckets[i];
+ hbucket bucket = oldbuckets[i];
- oldbuckets[i] = NULL;
+ oldbuckets[i] = NULL;
if (!hbucket_isNull (bucket))
{
for (j = 0; j < bucket->size; j++)
{
- cstringTable_addEntry (h, bucket->entries[j]);
+ cstringTable_addEntry (h, bucket->entries[j]);
}
/*
- ** evans 2001-03-24: new memory leak detected by LCLint
+ ** evans 2001-03-24: new memory leak detected by Splint
** after I fixed the checkCompletelyDestroyed.
*/
** instead reveals a bug I don't want to deal with right now!
*/
- if (hbucket_isNull (h->buckets[hindex]))
+ if (hbucket_isNull (h->buckets[hindex]))
{
- h->buckets[hindex] = hbucket_single (e);
+ h->buckets[hindex] = hbucket_single (e);
h->nentries++;
}
else
void
cstringTable_insert (cstringTable h, cstring key, int value)
{
- unsigned int hindex;
+ unsigned long hindex;
hbucket hb;
hentry e;
cstringTable_rehash (h);
}
- e = hentry_create (key, value);
hindex = cstringTable_hashValue (h, key);
+ e = hentry_create (key, value);
- hb = h->buckets[hindex];
+ hb = h->buckets[hindex];
if (hbucket_isNull (hb))
{
- h->buckets[hindex] = hbucket_single (e);
+ h->buckets[hindex] = hbucket_single (e);
}
else
{
for (i = 0; i < hb->size; i++)
{
- if (cstring_equal (hb->entries[i]->key, key))
+ if (cstring_equal (hb->entries[i]->key, key))
{
- hb->entries[i]->val = newval;
+ hb->entries[i]->val = newval;
return;
}
}
{
hbucket hb;
llassert (cstringTable_isDefined (h));
-
+
hb = cstringTable_hash (h, oldkey);
llassert (cstring_equal (oldkey, newkey));
for (i = 0; i < hb->size; i++)
{
- if (cstring_equal (hb->entries[i]->key, oldkey))
+ if (cstring_equal (hb->entries[i]->key, oldkey))
{
hb->entries[i]->key = newkey;
return;
for (i = 0; i < hb->size; i++)
{
- if (cstring_equal (hb->entries[i]->key, key))
+ if (cstring_equal (hb->entries[i]->key, key))
{
if (i < hb->size - 1)
{
- hb->entries[i] = hb->entries[hb->size - 1];
+ hb->entries[i] = hb->entries[hb->size - 1];
}
hb->size--;