]> andersk Git - splint.git/blobdiff - src/exprChecks.c
*** empty log message ***
[splint.git] / src / exprChecks.c
index e662771e5c7d4aacf0011e56068b28436a392ed1..4beef3aff84af32725768a5c935e22fc1efd1bcb 100644 (file)
@@ -638,7 +638,7 @@ void exprNode_checkMacroBody (/*@only@*/ exprNode e)
       uentry hdr;
 
       if (!(context_inFunctionLike () || context_inMacroConstant ()
-           || context_inMacroUnknown ()))
+           || context_inUnknownMacro ()))
        {
          llcontbug 
            (message 
@@ -732,7 +732,7 @@ void exprNode_checkMacroBody (/*@only@*/ exprNode e)
                }
            }
        }
-      else if (context_inMacroFunction () || context_inMacroUnknown ())
+      else if (context_inMacroFunction () || context_inUnknownMacro ())
        {
          ctype rettype = context_getRetType ();
 
@@ -921,23 +921,24 @@ void exprNode_checkFunction (/*@unused@*/ uentry ue, /*@only@*/ exprNode fcnBody
 
   /*@owned@*/ exprNode body;
 
- //  return;
-
- //  context_setFlag(FLG_ORCONSTRAINT, TRUE);
   context_enterInnerContext ();
 
   body = fcnBody;
 
-  // if we're not going to printing any errors for buffer buffer flows
-  //we can skip the checking to improve performance
-  //
-  //FLG_DEBUGFUNCTIONCONSTRAINT controls wheather we perform the check anyway
-  // in order to find potential problems like asserts and seg faults...
+  /*
+    if we're not going to be printing any errors for buffer overflows
+    we can skip the checking to improve performance
+    
+    FLG_DEBUGFUNCTIONCONSTRAINT controls wheather we perform the check anyway
+    in order to find potential problems like asserts and seg faults...
+  */
 
   if  (!context_getFlag(FLG_DEBUGFUNCTIONCONSTRAINT)  )
-    // check if errors will printed
+    /* check if errors will printed */
     if (! (context_getFlag(FLG_DEBUGFUNCTIONCONSTRAINT) ||
           context_getFlag(FLG_FUNCTIONCONSTRAINT) ||
+          context_getFlag(FLG_ARRAYBOUNDS) ||
+          context_getFlag(FLG_ARRAYBOUNDSREAD) ||
           context_getFlag(FLG_CHECKPOST) 
           )
        )
@@ -1008,6 +1009,8 @@ void exprNode_checkFunction (/*@unused@*/ uentry ue, /*@only@*/ exprNode fcnBody
                body->requiresConstraints = constraintList_reflectChangesFreePre (body->requiresConstraints, implicitFcnConstraints );
              }
      }
+
+   body->requiresConstraints = constraintList_sort (body->requiresConstraints);
    
    constraintList_printError(body->requiresConstraints, g_currentloc);
    
@@ -1050,18 +1053,25 @@ void exprNode_checkFunction (/*@unused@*/ uentry ue, /*@only@*/ exprNode fcnBody
      }
    
    if (constraintList_isDefined(post) )
-     constraintList_free(post);
+     {
+       constraintList_free(post);
+     }
    
+   body->ensuresConstraints = constraintList_sort(body->ensuresConstraints);
    
-   constraintList_printError(body->ensuresConstraints, g_currentloc);
+   if ( context_getFlag (FLG_FUNCTIONPOST) )
+     {
+       constraintList_printError(body->ensuresConstraints, g_currentloc);
+     }
    
    
-   //   ConPrint (message ("Unable to resolve function constraints:\n%s", constraintList_printDetailed(body->requiresConstraints) ), g_currentloc);
+   /*   ConPrint (message ("Unable to resolve function constraints:\n%s", constraintList_printDetailed(body->requiresConstraints) ), g_currentloc);
 
-   //   ConPrint (message ("LCLint has found function post conditions:\n%s", constraintList_printDetailed(body->ensuresConstraints) ), g_currentloc);
+       ConPrint (message ("LCLint has found function post conditions:\n%s", constraintList_printDetailed(body->ensuresConstraints) ), g_currentloc);
   
-     //  printf ("The required constraints are:\n%s", constraintList_printDetailed(body->requiresConstraints) );
-     //   printf ("The ensures constraints are:\n%s", constraintList_printDetailed(body->ensuresConstraints) );
+       printf ("The required constraints are:\n%s", constraintList_printDetailed(body->requiresConstraints) );
+       printf ("The ensures constraints are:\n%s", constraintList_printDetailed(body->ensuresConstraints) );
+   */
    
    if (constraintList_isDefined(c) )
      constraintList_free(c);
@@ -1077,7 +1087,7 @@ void exprChecks_checkEmptyMacroBody (void)
   uentry hdr;
   
   if (!(context_inFunctionLike () || context_inMacroConstant ()
-       || context_inMacroUnknown ()))
+       || context_inUnknownMacro ()))
     {
       llcontbug 
        (message ("exprNode_checkEmptyMacroBody: not in macro function or constant: %q", 
@@ -1513,6 +1523,16 @@ static void checkSafeReturnExpr (/*@notnull@*/ exprNode e)
   ctype tr = ctype_getReturnType (context_currentFunctionType ());
   ctype te = exprNode_getType (e);
 
+  /* evans 2001-08-21: added test to warn about void returns from void functions */
+  if (ctype_isVoid (tr))
+    {
+      (void) gentypeerror
+       (te, e, tr, exprNode_undefined,
+        message ("Return expression from function declared void: %s", exprNode_unparse (e)),
+        e->loc);
+      return;
+    }
+
   if (!ctype_forceMatch (tr, te) && !exprNode_matchLiteral (tr, e))
     {
       (void) gentypeerror
This page took 0.038465 seconds and 4 git commands to generate.