]> andersk Git - splint.git/blobdiff - src/constraintList.c
Made allocations involving sizeof work correctly (test/malloc.c).
[splint.git] / src / constraintList.c
index 99dc7e747e9b6438f50d6e731dec52fcca54cba2..ea2712149651648ca9e2dda3ad76196610e3f1e5 100644 (file)
@@ -31,8 +31,7 @@
 */
 
 # include "splintMacros.nf"
-# include "llbasic.h"
-
+# include "basic.h"
 
 /*@iter constraintList_elements_private_only (sef constraintList x, yield only constraint el); @*/
 # define constraintList_elements_private_only(x, m_el) \
@@ -60,7 +59,7 @@
   s->nspace = constraintListBASESIZE;
   s->elements = (constraint *)
     dmalloc (sizeof (*s->elements) * constraintListBASESIZE);
-
+  
   return (s);
 }
 
@@ -93,11 +92,14 @@ constraintList_add (/*@returned@*/ constraintList s, /*@only@*/ constraint el)
 
   /*drl7x */
 
-  if (constraintList_resolve (el, s) )
+  if (constraintList_resolve (el, s))
     {
+      DPRINTF (("Resolved constraint: %s", constraint_unparse (el)));
       constraint_free (el);
       return s;
     }
+
+  DPRINTF (("Adding constraint: %s", constraint_unparse (el)));
   
   if (s->nspace <= 0)
     constraintList_grow (s);
@@ -127,15 +129,15 @@ static void constraintList_freeShallow (/*@only@*/ constraintList c)
 
 /*@only@*/ constraintList constraintList_addList (/*@only@*/ /*@returned@*/ constraintList s, /*@observer@*/ /*@temp@*/ constraintList newList)
 {
-  llassert(constraintList_isDefined(s) );
-  llassert(constraintList_isDefined(newList) );
+  llassert(constraintList_isDefined (s));
+  llassert(constraintList_isDefined (newList));
 
   if (newList == constraintList_undefined)
     return s;
   
   constraintList_elements (newList, elem)
     {
-    s = constraintList_add (s, constraint_copy(elem) );
+      s = constraintList_add (s, constraint_copy(elem));
     }
   end_constraintList_elements;
 
@@ -144,32 +146,30 @@ static void constraintList_freeShallow (/*@only@*/ constraintList c)
 
 constraintList constraintList_addListFree (/*@returned@*/ constraintList s, /*@only@*/ constraintList newList)
 {
-  llassert(constraintList_isDefined(s) );
-  llassert(constraintList_isDefined(newList) );
-
-  if (constraintList_isUndefined(newList) )
+  if (constraintList_isUndefined (newList))
     return s;
+
+  llassert (constraintList_isDefined (s));
+  llassert (constraintList_isDefined (newList));
   
   constraintList_elements_private_only(newList, elem)
     {
-    s = constraintList_add (s, elem);
-    }
-  end_constraintList_elements_private_only
-
-    constraintList_freeShallow(newList);
-    return s;
+      s = constraintList_add (s, elem);
+    } end_constraintList_elements_private_only;
+  
+  constraintList_freeShallow (newList);
+  return s;
 }
 
-
 constraintList constraintList_removeSurpressed (/*@only@*/ constraintList s)
 {
   constraintList ret;
   fileloc loc;
-  llassert(constraintList_isDefined(s) );
 
+  llassert (constraintList_isDefined (s));
   ret = constraintList_makeNew();
   
-  constraintList_elements_private_only(s, elem)
+  constraintList_elements_private_only (s, elem)
     {
       loc = constraint_getFileloc(elem);
 
@@ -177,18 +177,16 @@ constraintList constraintList_removeSurpressed (/*@only@*/ constraintList s)
        {
          ret = constraintList_add (ret, elem);
        }
-      
       else if (context_suppressFlagMsg(FLG_BOUNDSWRITE, loc) )
        {
          DPRINTF ((message ("constraintList_removeSurpressed getting rid of surpressed constraint %q", 
-                            constraint_print(elem))));
+                            constraint_unparse(elem))));
          constraint_free(elem);
        }
-      
       else if (!constraint_hasMaxSet(elem) && context_suppressFlagMsg(FLG_BOUNDSREAD, loc))
        {
          DPRINTF ((message("constraintList_removeSurpressed getting rid of surpressed constraint %q", 
-                           constraint_print(elem))));
+                           constraint_unparse(elem))));
          constraint_free(elem);
        }
       else
@@ -196,23 +194,15 @@ constraintList constraintList_removeSurpressed (/*@only@*/ constraintList s)
          ret = constraintList_add (ret, elem);
        } 
       fileloc_free(loc);
-    } 
-  end_constraintList_elements_private_only;
+    } end_constraintList_elements_private_only;
 
   constraintList_freeShallow(s);
-  
   return ret;
 }
 
-
-extern /*@only@*/ cstring constraintList_unparse ( /*@observer@*/ constraintList s) /*@*/
-{
-  return (constraintList_print(s));
-}
-
 # if 0
 static /*@only@*/ cstring
-constraintList_printLocation (/*@temp@*/ constraintList s) /*@*/
+constraintList_unparseLocation (/*@temp@*/ constraintList s) /*@*/
 {
   int i;
   cstring st = cstring_undefined;
@@ -237,7 +227,7 @@ constraintList_printLocation (/*@temp@*/ constraintList s) /*@*/
       if (constraint_isDefined(current) )
        {
          cstring temp1;
-             temp1 = constraint_printLocation(current);
+             temp1 = constraint_unparseLocation(current);
          type = message ("%q %q\n", type, temp1 );
        }
 
@@ -257,7 +247,7 @@ constraintList_printLocation (/*@temp@*/ constraintList s) /*@*/
 # endif
 
 /*@only@*/ cstring
-constraintList_print (/*@temp@*/ constraintList s) /*@*/
+constraintList_unparse (/*@temp@*/ constraintList s) /*@*/
 {
   int i;
   cstring st = cstring_undefined;
@@ -282,10 +272,15 @@ constraintList_print (/*@temp@*/ constraintList s) /*@*/
       if (constraint_isDefined(current) )
        {
          cstring temp1;
-           if ( context_getFlag (FLG_ORCONSTRAINT) )
-             temp1 = constraint_printOr(current);
-           else
-             temp1 = constraint_print(current);
+
+         if (context_getFlag (FLG_ORCONSTRAINT))
+           {
+             temp1 = constraint_unparseOr (current);
+           }
+         else
+           {
+             temp1 = constraint_unparse (current);
+           }
          type = message ("%q %q\n", type, temp1 );
        }
 
@@ -336,7 +331,7 @@ void constraintList_printError (constraintList s, fileloc loc)
 
 
 cstring
-constraintList_printDetailed (constraintList s)
+constraintList_unparseDetailed (constraintList s)
 {
   int i;
   cstring st = cstring_undefined;
@@ -360,7 +355,7 @@ constraintList_printDetailed (constraintList s)
 
       if (constraint_isDefined(current ) )
        {
-         cstring temp1 = constraint_printDetailed (current);
+         cstring temp1 = constraint_unparseDetailed (current);
          type = message ("%s %s\n", type, temp1 );
          cstring_free(temp1);
        }
@@ -388,8 +383,8 @@ constraintList_logicalOr (/*@observer@*/ constraintList l1, /*@observer@*/ const
   constraint temp;
   constraintList ret;
   DPRINTF ((message ("Logical or on %s and %s",
-                     constraintList_print(l1), 
-                     constraintList_print(l2)) ) );
+                     constraintList_unparse(l1), 
+                     constraintList_unparse(l2)) ) );
   
   ret = constraintList_makeNew();
   constraintList_elements (l1, el)
@@ -434,22 +429,22 @@ constraintList_logicalOr (/*@observer@*/ constraintList l1, /*@observer@*/ const
 void
 constraintList_free (/*@only@*/ constraintList s)
 {
-  int i;
-
-  llassert(constraintList_isDefined(s) );
-
-  
-  for (i = 0; i < s->nelements; i++)
+  if (constraintList_isDefined (s))
     {
-      constraint_free (s->elements[i]); 
+      int i;
+      
+      for (i = 0; i < s->nelements; i++)
+       {
+         constraint_free (s->elements[i]); 
+       }
+      
+      sfree (s->elements);
+      s->elements = NULL;
+      s->nelements = -1;
+      s->nspace = -1;
+      sfree (s);
+      s = NULL;
     }
-
-  sfree (s->elements);
-  s->elements = NULL;
-  s->nelements = -1;
-  s->nspace = -1;
-  sfree (s);
-  s = NULL;
 }
 
 constraintList
@@ -467,7 +462,7 @@ constraintList_copy (/*@observer@*/ /*@temp@*/ constraintList s)
 
 constraintList constraintList_preserveOrig (constraintList c)
 {
-  DPRINTF((message("constraintList_preserveOrig preserving the originial constraints for %s ", constraintList_print (c) ) ));
+  DPRINTF((message("constraintList_preserveOrig preserving the originial constraints for %s ", constraintList_unparse (c) ) ));
 
   constraintList_elements_private (c, el)
   {
@@ -479,7 +474,7 @@ constraintList constraintList_preserveOrig (constraintList c)
 
 constraintList constraintList_preserveCallInfo (/*@returned@*/ constraintList c,/*@observer@*/ /*@dependent@*/ /*@observer@*/  exprNode fcn)
 {
-  DPRINTF((message("constraintList_preserveCallInfo %s ", constraintList_print (c) ) ));
+  DPRINTF((message("constraintList_preserveCallInfo %s ", constraintList_unparse (c) ) ));
 
   constraintList_elements_private (c, el)
   {
@@ -504,7 +499,7 @@ constraintList constraintList_addGeneratingExpr (constraintList c,/*@dependent@*
   
   constraintList_elements_private (c, el)
   {
-    DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print(el), exprNode_unparse(e) )  ));
+    DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_unparse(el), exprNode_unparse(e) )  ));
     el = constraint_addGeneratingExpr (el, e);
   }
   end_constraintList_elements_private;
@@ -608,6 +603,12 @@ constraintList constraintList_togglePost (/*@returned@*/ constraintList c)
 
       c =  reader_getWord(&s);
       
+      if (! mstring_isDefined(c) )
+       {
+         llfatalbug(message("Library file is corrupted") );
+       }
+  
+
       if (strcmp (c, "C") != 0)
        {
          llfatalbug(message("Error reading library.  File may be corrupted"));
@@ -634,9 +635,14 @@ void constraintList_dump (/*@observer@*/ constraintList c,  FILE *f)
   end_constraintList_elements; ;
 }
 
-
 constraintList constraintList_sort (/*@returned@*/ constraintList ret)
 {
+  if (constraintList_isUndefined(ret) )
+    {
+      llassert(FALSE);
+      return ret;
+    }
+
   qsort (ret->elements, (size_t) ret->nelements,
         (sizeof (*ret->elements)), 
         (int (*)(const void *, const void *)) constraint_compare);
This page took 0.046489 seconds and 4 git commands to generate.