X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/2209bcb718c2285ba4302cc89388e9f098f84d15..HEAD:/src/general.c diff --git a/src/general.c b/src/general.c index c799195..da2bb57 100644 --- a/src/general.c +++ b/src/general.c @@ -1,6 +1,6 @@ /* -** 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 @@ -17,16 +17,17 @@ ** 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 */ /* ** general.c */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "basic.h" + # undef malloc # undef realloc # undef calloc @@ -35,7 +36,7 @@ # include "dmalloc.h" # endif -# include "portab.h" +# include "osd.h" /* ** redefine undef'd memory ops @@ -86,6 +87,7 @@ static long unsigned size_toLongUnsigned (size_t x) } /*@out@*/ void *dimalloc (size_t size, const char *name, int line) + /*@ensures maxSet(result) == (size - 1); @*/ { /* static void *lastaddr = 0; @@ -112,8 +114,15 @@ static long unsigned size_toLongUnsigned (size_t x) { if (size == 0) { - llbug (message ("Zero allocation at %q.", - fileloc_unparseRaw (cstring_fromChars (name), line))); + llcontbug (message ("Zero allocation at %q.", + fileloc_unparseRaw (cstring_fromChars (name), line))); + + /* + ** evans 2002-03-01 + ** Return some allocated storage...hope we get lucky. + */ + + return dimalloc (16, name, line); } else { @@ -179,21 +188,6 @@ void *direalloc (/*@out@*/ /*@null@*/ void *x, size_t size, /*@=mustdefine@*/ -# ifndef NOLCL -char *FormatInt (int i) -{ - char temp[255]; /* assume the integer has at most 254 digits */ - char *outs; - - sprintf (temp, "%i", i); - outs = (char *) dmalloc (sizeof (*outs) * (1 + strlen (temp))); - strcpy (outs, temp); - - return (outs); -} -# endif - -# ifndef NOLCL bool firstWord (char *s, char *w) { llassert (s != NULL); @@ -206,7 +200,6 @@ bool firstWord (char *s, char *w) } return TRUE; } -# endif void mstring_markFree (char *s) { @@ -306,7 +299,7 @@ mstring_append (/*@only@*/ char *s1, char c) } extern -char *mstring_copy (char *s1) +char *mstring_copy (char *s1) /*@ensures maxRead(result) == maxRead(s1) /\ maxSet(result) == maxSet(s1) @*/ { if (s1 == NULL) { @@ -334,7 +327,7 @@ char *mstring_safePrint (char *s) } extern -char *mstring_create (int n) +char *mstring_create (size_t n) { char *s; @@ -354,6 +347,12 @@ fputline (FILE *out, char *s) check (fputc ('\n', out) == (int) '\n'); } +unsigned int int_toNonNegative (int x) /*@*/ +{ + llassert (x >= 0); + return (unsigned) x; +} + int int_log (int x) { int ret = 1; @@ -376,7 +375,7 @@ longUnsigned_fromInt (int x) return (long unsigned) x; } -size_t size_fromInt (int x) +size_t size_fromInt (int x) /*@ensures result==x@*/ { size_t res = (size_t) x; @@ -384,6 +383,22 @@ size_t size_fromInt (int x) return res; } +size_t size_fromLong (long x) /*@ensures result==x@*/ +{ + size_t res = (size_t) x; + + llassert ((long) res == x); + return res; +} + +size_t size_fromLongUnsigned (unsigned long x) /*@ensures result==x@*/ +{ + size_t res = (size_t) x; + + llassert ((unsigned long) res == x); + return res; +} + int size_toInt (size_t x) { int res = (int) x;