]> andersk Git - splint.git/blobdiff - src/general.c
Merged this branch with the one in the splint.sf.net repository.
[splint.git] / src / general.c
index bf3eb83d0392cdefb6cd32f41bdfc2c5c009c160..c6595dcfb44d8e888f7fec1ff5ea350db0cd3ac2 100644 (file)
@@ -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-2002 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
 */
 /*
 ** general.c
 */
 
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # include "basic.h"
 # undef malloc
 # undef realloc
@@ -86,6 +86,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 +113,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
        {
@@ -210,7 +218,7 @@ bool firstWord (char *s, char *w)
 
 void mstring_markFree (char *s)
 {
-    sfreeEventually (s);
+  sfreeEventually (s);
 }
 
 char *mstring_spaces (int n)
@@ -245,6 +253,18 @@ bool mstring_containsChar (const char *s, char c)
       return FALSE;
     }
 }
+
+bool mstring_containsString (const char *s, const char *c)
+{
+  if (mstring_isDefined (s))
+    {
+      return (strstr (s, c) != NULL);
+    }
+  else
+    {
+      return FALSE;
+    }
+}
  
 char *mstring_concat (const char *s1, const char *s2)
 {
@@ -294,7 +314,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)
     {
@@ -322,7 +342,7 @@ char *mstring_safePrint (char *s)
 }
 
 extern
-char *mstring_create (int n)
+char *mstring_create (size_t n)
 {
   char *s;
 
@@ -342,6 +362,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;
@@ -364,7 +390,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;
 
@@ -393,9 +419,15 @@ long size_toLong (size_t x)
 char
 char_fromInt (int x)
 {
-  llassert ((x >= (int)'\0') && (x <= (int)'~'));
+  /*
+  ** evans 2001-09-28 - changed assertion in response to Anthony Giorgio's comment 
+  ** that the old assertions failed for EBCDIC character set.  Now we just check 
+  ** that the result is equal.
+  */
 
-  return ((char) x);
+  char res = (char) x;
+  llassert ((int) res == x);
+  return res;
 }
 
 /*@-czechfcns@*/
@@ -453,3 +485,28 @@ bool mstring_equal (/*@null@*/ const char *s1, /*@null@*/ const char *s2)
     }
 }
 
+/*drl added 4-15-2002 intened to be called on file names*/
+bool cstring_isDotH (cstring name)
+{
+  char lastCh;
+
+  /* fix this function.*/
+  
+  char * waste = malloc(10); /*remove this line*/
+    
+  DPRINTF((message("cstrint_isDotH: %s ", name) ) );
+  
+  lastCh = cstring_lastChar(name);
+  // Fix this
+  
+  if ( (lastCh == 'h') || (lastCh == 'r') )
+    {
+      DPRINTF((message("cstrint_isDotH: %s is .h ", name) ) );
+      return TRUE;
+    }
+  else
+    {
+      DPRINTF((message("cstrint_isDotH: %s is not .h", name) ) );
+      return FALSE;
+    }
+}
This page took 0.120121 seconds and 4 git commands to generate.