]> andersk Git - splint.git/blobdiff - src/transferChecks.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / transferChecks.c
index aa2dd4d4cf7e3728c5bfc648433df786e2d9eb60..d77e7c3869874355cf37fd1eb322c24c07af113a 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-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
 */
 /*
 ** transferChecks.c
 */
 
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # include "basic.h"
 # include "transferChecks.h"
 
+/* transfer types: */
+typedef enum
+{
+  TT_FCNRETURN,
+  TT_DOASSIGN,
+  TT_FIELDASSIGN,
+  TT_FCNPASS,
+  TT_GLOBPASS,
+  TT_GLOBRETURN,
+  TT_PARAMRETURN,
+  TT_LEAVETRANS,
+  TT_GLOBINIT
+} transferKind;
+
 static void checkStructTransfer (exprNode p_lhs, sRef p_slhs, exprNode p_rhs, sRef p_srhs,
                                 fileloc p_loc, transferKind p_tt);
 static void checkMetaStateConsistent (/*@exposed@*/ sRef p_fref, sRef p_tref, 
@@ -305,7 +319,7 @@ checkCompletelyDefined (exprNode fexp, /*@exposed@*/ sRef fref, sRef ofref,
         ("Check definition limit exceeded, checking %q. "
          "This either means there is a variable with at least "
          "%d indirections apparent in the program text, or "
-         "there is a bug in LCLint.",
+         "there is a bug in Splint.",
          sRef_unparse (fref),
          MAXDEPTH));
 
@@ -491,7 +505,8 @@ checkCompletelyDefined (exprNode fexp, /*@exposed@*/ sRef fref, sRef ofref,
            {
              ; /* no error (will be a definition error) */
            }
-         else if (transferType == TT_DOASSIGN)
+         else if (transferType == TT_DOASSIGN
+                  || transferType == TT_FIELDASSIGN) /* evans 2002-02-05 - added TT_FIELDASSIGN */
            {
              ; /* no error */
            }
@@ -761,6 +776,7 @@ checkCompletelyDefined (exprNode fexp, /*@exposed@*/ sRef fref, sRef ofref,
       else
        {
          llassert (transferType == TT_DOASSIGN
+                   || transferType == TT_FIELDASSIGN /* evans 2002-02-05: no warnings for local fields */
                    || transferType == TT_GLOBINIT
                    || transferType == TT_LEAVETRANS);
        }
@@ -880,10 +896,8 @@ checkCompletelyDefined (exprNode fexp, /*@exposed@*/ sRef fref, sRef ofref,
                        {
                          sRef rb = sRef_getRootBase (fref);
                          sRef_showStateInfo (fref);
-
-                         DPRINTF (("fref: %s", sRef_unparseFull (fref)));
-                         DPRINTF (("rb: %s", sRef_unparseFull (rb)));
-                         sRef_setDefinedComplete (rb, loc);
+                         
+                         sRef_setDefinedCompleteDirect (rb, loc);
                        }
                    }
                }
@@ -1274,17 +1288,18 @@ static /*@observer@*/ cstring dscCode_unparse (dscCode desc) /*@*/
 }
 
 static bool 
-  checkCompletelyDestroyed (exprNode p_fexp, sRef p_fref, bool p_topLevel, 
-                           fileloc p_loc, int p_depth, dscCode p_desc,
-                           bool p_hideErrors);
+checkCompletelyDestroyed (exprNode p_fexp, sRef p_fref, bool p_topLevel, bool p_isField,
+                         fileloc p_loc, int p_depth, dscCode p_desc,
+                         bool p_hideErrors);
 
-bool checkGlobalDestroyed (sRef fref, fileloc loc)
+bool transferChecks_globalDestroyed (sRef fref, fileloc loc)
 {
-  return (checkCompletelyDestroyed (exprNode_undefined, fref, TRUE,
+  DPRINTF (("Global destroyed: %s", sRef_unparseFull (fref)));
+  return (checkCompletelyDestroyed (exprNode_undefined, fref, TRUE, FALSE,
                                    loc, 0, DSC_GLOB, FALSE));
 }
 
-void checkLocalDestroyed (sRef fref, fileloc loc)
+void transferChecks_localDestroyed (sRef fref, fileloc loc)
 {
   if (sRef_isObserver (fref) || sRef_isExposed (fref)
       || sRef_isPartial (fref))
@@ -1293,12 +1308,12 @@ void checkLocalDestroyed (sRef fref, fileloc loc)
     }
   else
     {
-      (void) checkCompletelyDestroyed (exprNode_undefined, fref, TRUE,
+      (void) checkCompletelyDestroyed (exprNode_undefined, fref, TRUE, FALSE,
                                       loc, 0, DSC_LOCAL, FALSE);
     }
 }
 
-void checkStructDestroyed (sRef fref, fileloc loc)
+void transferChecks_structDestroyed (sRef fref, fileloc loc)
 {
   DPRINTF (("Check struct destroyed: %s", sRef_unparse (fref)));
 
@@ -1309,19 +1324,21 @@ void checkStructDestroyed (sRef fref, fileloc loc)
     }
   else
     {
-      (void) checkCompletelyDestroyed (exprNode_undefined, fref, TRUE,
+      (void) checkCompletelyDestroyed (exprNode_undefined, fref, TRUE, FALSE,
                                       loc, 0, DSC_STRUCT, FALSE);
     }
 }
 
 static bool
-  checkCompletelyDestroyed (exprNode fexp, sRef fref, bool topLevel,
-                           fileloc loc, int depth,
-                           dscCode desc, bool hideErrors)
+checkCompletelyDestroyed (exprNode fexp, sRef fref, bool topLevel, bool isField,
+                         fileloc loc, int depth,
+                         dscCode desc, bool hideErrors)
 {
   ctype ct;
-
-  DPRINTF (("Check completely destroyed: %s", sRef_unparseFull (fref)));
+  
+  DPRINTF (("Check completely destroyed: %s / %s",
+           sRef_unparse (fref),
+           bool_unparse (hideErrors)));
 
   if (depth > MAXDEPTH)
     {
@@ -1377,23 +1394,40 @@ static bool
       }
   }
 
-  if (sRef_isPdefined (fref) && !context_getFlag (FLG_STRICTDESTROY))
+  ct = ctype_realType (sRef_getType (fref));
+
+  if (sRef_isPdefined (fref) 
+      && ctype_isAP (ct)
+      && !isField
+      && !context_getFlag (FLG_STRICTDESTROY))
     {
-      DPRINTF (("Partial: %s", sRef_unparseFull (fref)));
-      hideErrors = TRUE; /* Don't report any more errors, but still change ownership. */
-    }
+      /*
+      ** Don't report errors for array elements (unless strictdestroy)
+      ** when at least one appears to have been destroyed.
+      */
 
+      DPRINTF (("Partial: %s / hiding errors: %s", sRef_unparseFull (fref),
+               ctype_unparse (ct)));
+      hideErrors = TRUE;
+      /* Don't report any more errors, but still change ownership. */
+    }
+  
   if (usymtab_isDefinitelyNull (fref)) 
     {
       DPRINTF (("Probably null!"));
       return TRUE;
     }
 
-  if (!context_getFlag (FLG_COMPDESTROY)) return TRUE;
-  if (!context_getFlag (FLG_MUSTFREE)) return TRUE;
+  /*
+  ** evans 2002-01-02: removed this
+  ** if (!context_flagOn (FLG_COMPDESTROY, loc)) 
+  ** {
+  ** return TRUE;
+  ** }
+  ** 
+  ** if (!context_getFlag (FLG_MUSTFREEONLY)) return TRUE;
+  */
   
-  ct = ctype_realType (sRef_getType (fref));
-
   DPRINTF (("Here: %s", ctype_unparse (ct)));
 
   if (!topLevel)
@@ -1511,7 +1545,7 @@ static bool
          return FALSE;
        }
       
-      if (/*! evs-2001-03-24 sRef_isAnyDefined (fref) || */
+      if (/*! evs-2002-03-24 sRef_isAnyDefined (fref) || */
          sRef_isDead (fref)
          || (sRef_isPdefined (fref) 
              && sRefSet_isEmpty (sRef_derivedFields (fref)))) 
@@ -1531,8 +1565,8 @@ static bool
       sRef fptr = sRef_constructDeadDeref (fref);
       bool res;
 
-      res = checkCompletelyDestroyed (fexp, fptr, FALSE, loc,
-                                     depth + 1, desc, hideErrors);
+      res = checkCompletelyDestroyed (fexp, fptr, FALSE, FALSE,
+                                     loc, depth + 1, desc, hideErrors);
       
       return res;
     }
@@ -1551,8 +1585,8 @@ static bool
        {
          sRef farr = sRef_constructDeadDeref (fref);
          
-         return (checkCompletelyDestroyed (fexp, farr, FALSE, loc, 
-                                           depth + 1, desc, hideErrors));
+         return (checkCompletelyDestroyed (fexp, farr, FALSE, FALSE,
+                                           loc, depth + 1, desc, hideErrors));
        }
     }
   else if (ctype_isStruct (ct))
@@ -1586,12 +1620,12 @@ static bool
              
              DPRINTF (("Check field: %s", sRef_unparseFull (field)));
 
-             isOk = (checkCompletelyDestroyed (fexp, field, FALSE, loc,
-                                               depth + 1, desc, hideErrors)
+             isOk = (checkCompletelyDestroyed (fexp, field, FALSE, TRUE,
+                                               loc, depth + 1, desc, hideErrors)
                      && isOk);
            } end_uentryList_elements;
        }
-
+      
       return isOk;
     }
   else
@@ -1601,7 +1635,7 @@ static bool
 }
 
 void
-checkReturnTransfer (exprNode fexp, uentry rval)
+transferChecks_return (exprNode fexp, uentry rval)
 {
   sRef uref = uentry_getSref (rval);
   sRef rref = sRef_makeNew (sRef_getType (uref), uref, cstring_undefined);
@@ -1623,7 +1657,7 @@ checkReturnTransfer (exprNode fexp, uentry rval)
     {
       if (stateClause_isGlobal (cl))
        {
-         ; /*@i32@*/
+         ; 
        }
       else if (stateClause_setsMetaState (cl))
        {
@@ -1661,7 +1695,6 @@ checkReturnTransfer (exprNode fexp, uentry rval)
                           exprNode_loc (fexp)))
                        {
                          sRef_showAliasInfo (sr); 
-                         /*@i32@*/
                        }
                    }
                }
@@ -1690,7 +1723,8 @@ checkReturnTransfer (exprNode fexp, uentry rval)
              DPRINTF (("el: %s / %s", sRef_unparse (el),
                        sRef_unparse (base)));
              
-             if (sRef_isResult (base))
+             if (sRef_isResult (base) 
+                 && !sRef_isDefinitelyNull (fref)) /* evans 2002-07-22: don't report allocation errors for null results */
                {
                  sRef sr = sRef_fixBase (el, fref);
                  
@@ -1827,8 +1861,8 @@ static void
 */
 
 void
-checkPassTransfer (exprNode fexp, uentry arg, bool isSpec,
-                  /*@dependent@*/ exprNode fcn, int argno, int totargs)
+transferChecks_passParam (exprNode fexp, uentry arg, bool isSpec,
+                         /*@dependent@*/ exprNode fcn, int argno, int totargs)
 {
   sRef tref = uentry_getSref (arg);
   sRef fref = exprNode_getSref (fexp);
@@ -1916,8 +1950,8 @@ checkPassTransfer (exprNode fexp, uentry arg, bool isSpec,
            }
        }
       
-      (void) checkCompletelyDestroyed (fexp, fref, TRUE, exprNode_loc (fexp),
-                                      0, DSC_PARAM, FALSE);
+      (void) checkCompletelyDestroyed (fexp, fref, TRUE, FALSE,
+                                      exprNode_loc (fexp), 0, DSC_PARAM, FALSE);
 
       /* make it defined now, so checkTransfer is okay */
       sRef_setDefined (fref, exprNode_loc (fexp)); 
@@ -2134,13 +2168,14 @@ checkPassTransfer (exprNode fexp, uentry arg, bool isSpec,
        
        {
          voptgenerror 
-           (FLG_MUSTFREE,
+           (FLG_MUSTFREEFRESH,
             message ("New fresh storage %q(type %s) passed as %s (not released): %s",
                      sRef_unparseOpt (fref),
                      ctype_unparse (sRef_getType (fref)),
                      alkind_unparse (sRef_getAliasKind (tref)),
                      exprNode_unparse (fexp)),
             exprNode_loc (fexp));
+
          DPRINTF (("Fresh: %s", sRef_unparseFull (fref)));
        }
       else 
@@ -2152,7 +2187,7 @@ checkPassTransfer (exprNode fexp, uentry arg, bool isSpec,
              if (!alkind_isError (ak))
                {
                  voptgenerror 
-                   (FLG_MUSTFREE,
+                   (FLG_MUSTFREEFRESH,
                     message ("New reference %q(type %s) passed as %s (not released): %s",
                              sRef_unparseOpt (fref),
                              ctype_unparse (sRef_getType (fref)),
@@ -2229,19 +2264,19 @@ checkPassTransfer (exprNode fexp, uentry arg, bool isSpec,
 }
 
 void
-checkGlobReturn (uentry glob)
+transferChecks_globalReturn (uentry glob)
 {
   sRef_protectDerivs ();
   checkGlobTrans (glob, TT_GLOBRETURN);
   sRef_clearProtectDerivs ();
 }
 
-void checkParamReturn (uentry actual)
+void transferChecks_paramReturn (uentry actual)
 {
   checkLeaveTrans (actual, TT_PARAMRETURN);
 }
 
-void checkLoseRef (uentry actual)
+void transferChecks_loseReference (uentry actual)
 {
   checkLeaveTrans (actual, TT_LEAVETRANS);
 }
@@ -2281,8 +2316,11 @@ static void
 checkGlobTrans (uentry glob, transferKind type)
 {
   sRef eref = uentry_getOrigSref (glob);
-  
-  (void) checkCompletelyDefined (exprNode_undefined, uentry_getSref (glob), uentry_getSref (glob),
+  DPRINTF (("Completely defined: %s", uentry_unparseFull (glob)));
+
+  (void) checkCompletelyDefined (exprNode_undefined, uentry_getSref (glob), 
+                                uentry_getSref (glob),
                                 exprNode_undefined, eref, 
                                 TRUE, FALSE, FALSE,
                                 g_currentloc, type, 0, TRUE);
@@ -2370,7 +2408,7 @@ static void checkStructTransfer (exprNode lhs, sRef slhs, exprNode rhs, sRef srh
 }
 
 void
-checkInitTransfer (exprNode lhs, exprNode rhs)
+transferChecks_initialization (exprNode lhs, exprNode rhs)
 {
   sRef slhs = exprNode_getSref (lhs);
   
@@ -2383,12 +2421,12 @@ checkInitTransfer (exprNode lhs, exprNode rhs)
     }
   else
     {
-      checkAssignTransfer (lhs, rhs);
+      transferChecks_assign (lhs, rhs);
     }
 }
 
 void
-checkAssignTransfer (exprNode lhs, exprNode rhs)
+transferChecks_assign (exprNode lhs, exprNode rhs)
 {
   sRef slhs = exprNode_getSref (lhs);
   sRef srhs = exprNode_getSref (rhs);
@@ -2496,7 +2534,7 @@ checkTransferNullAux (sRef fref, exprNode fexp, /*@unused@*/ bool ffix,
              if (sRef_isNotNull (tref))
                {
                  if (optgenerror
-                     (FLG_SYNTAX, /*@i432 kuldge flag... */
+                     (FLG_NULLINIT, /* kuldge flag... */
                       message ("%s %q initialized to %s value: %q",
                                sRef_getScopeName (tref),
                                sRef_unparse (tref),
@@ -2578,83 +2616,82 @@ checkTransferAssignAux (sRef fref, exprNode fexp, /*@unused@*/ bool ffix,
       && !(sRef_same (fref, tref)) /* okay to assign to self (returned params) */
       && !(usymtab_isDefinitelyNull (tref))) 
     {
-      if (context_getFlag (FLG_MUSTFREE))
+      if (transferChecks_canLoseReference (tref, loc))
        {
-         if (canLoseReference (tref, loc))
+         ; /* no error */
+       }
+      else
+       {
+         flagcode flg = sRef_isFresh (tref) ? FLG_MUSTFREEFRESH : FLG_MUSTFREEONLY;
+
+         if (sRef_hasLastReference (tref))
            {
-             ; /* no error */
+             if (optgenerror 
+                 (flg,
+                  message ("Last reference %q to %s storage %q(type %s) not released "
+                           "before assignment: %q",
+                           sRef_unparse (tref),
+                           alkind_unparse (tkind),
+                           sRef_unparseOpt (sRef_getAliasInfoRef (tref)),
+                           ctype_unparse (sRef_getType (tref)),
+                           generateText (fexp, texp, tref, transferType)),
+                  loc))
+               {
+                 sRef_showRefLost (tref);
+               }
            }
          else
            {
-             if (sRef_hasLastReference (tref))
+             if (context_inGlobalScope ())
                {
-                 if (optgenerror 
-                     (FLG_MUSTFREE,
-                      message ("Last reference %q to %s storage %q(type %s) not released "
-                               "before assignment: %q",
-                               sRef_unparse (tref),
-                               alkind_unparse (tkind),
-                               sRef_unparseOpt (sRef_getAliasInfoRef (tref)),
-                               ctype_unparse (sRef_getType (tref)),
-                               generateText (fexp, texp, tref, transferType)),
-                      loc))
-                   {
-                     sRef_showRefLost (tref);
-                   }
+                 /* no errors for static initializations */
                }
-             else
+             else 
                {
-                 if (context_inGlobalScope ())
-                   {
-                     /* no errors for static initializations */
-                   }
-                 else 
+                 /*
+                 ** don't report this error for a[i], since it could
+                 ** be a new element.
+                 */
+                 
+                 if (alkind_isNewRef (tkind))
                    {
-                     /*
-                      ** don't report this error for a[i], since it could
-                      ** be a new element.
-                      */
-                     
-                     if (alkind_isNewRef (tkind))
-                       {
-                         if (optgenerror 
-                             (FLG_MUSTFREE,
-                              message 
-                              ("%q %q(type %s) not released before assignment: %q",
-                               cstring_makeLiteral
-                               (alkind_isKillRef (sRef_getOrigAliasKind (tref))
-                                ? "Kill reference parameter" : "New reference"),
-                               sRef_unparseOpt (tref),
-                               ctype_unparse (sRef_getType (tref)),
-                               generateText (fexp, texp, tref, transferType)),
-                              loc))
-                           {
-                             sRef_showAliasInfo (tref);
-                             sRef_setAliasKind (tref, AK_ERROR, loc);
-                           }
-                       }
-                     else if
-                       (!(sRef_isUnknownArrayFetch (tref)
-                          && !context_getFlag (FLG_STRICTDESTROY))
-                        && !sRef_isUnionField (tref)
-                        && !sRef_isRelDef (tref)
-                        && optgenerror 
-                        (FLG_MUSTFREE,
-                         message 
-                         ("%s storage %q(type %s) not released before assignment: %q",
-                          alkind_capName (tkind),
-                          sRef_unparseOpt (tref),
-                          ctype_unparse (sRef_getType (tref)),
-                          generateText (fexp, texp, tref, transferType)),
-                         loc))
-                         {
-                           sRef_showAliasInfo (tref);
-                         }
-                     else
+                     if (optgenerror 
+                         (flg,
+                          message 
+                          ("%q %q(type %s) not released before assignment: %q",
+                           cstring_makeLiteral
+                           (alkind_isKillRef (sRef_getOrigAliasKind (tref))
+                            ? "Kill reference parameter" : "New reference"),
+                           sRef_unparseOpt (tref),
+                           ctype_unparse (sRef_getType (tref)),
+                           generateText (fexp, texp, tref, transferType)),
+                          loc))
                        {
-                         ;
+                         sRef_showAliasInfo (tref);
+                         sRef_setAliasKind (tref, AK_ERROR, loc);
                        }
                    }
+                 else if
+                   (!(sRef_isUnknownArrayFetch (tref)
+                      && !context_getFlag (FLG_STRICTDESTROY))
+                    && !sRef_isUnionField (tref)
+                    && !sRef_isRelDef (tref)
+                    && optgenerror 
+                    (flg,
+                     message 
+                     ("%s storage %q(type %s) not released before assignment: %q",
+                      alkind_capName (tkind),
+                      sRef_unparseOpt (tref),
+                      ctype_unparse (sRef_getType (tref)),
+                      generateText (fexp, texp, tref, transferType)),
+                     loc))
+                   {
+                     sRef_showAliasInfo (tref);
+                   }
+                 else
+                   {
+                     ;
+                   }
                }
            }
        }
@@ -3861,7 +3898,7 @@ checkTransferAux (exprNode fexp, /*@exposed@*/ sRef fref, bool ffix,
              && ctype_isMutable (exprNode_getType (fexp))
              && (!iseitherassign || sRef_isReference (tref)))
            {
-             if (canLoseReference (fref, loc))
+             if (transferChecks_canLoseReference (fref, loc))
                {
                  ;
                }
@@ -4101,7 +4138,7 @@ checkMetaStateConsistent (/*@exposed@*/ sRef fref, sRef tref,
 static void
 checkMetaStateTransfer (exprNode fexp, sRef fref, exprNode texp, sRef tref, 
                        exprNode fcn,
-                       fileloc loc, transferKind /*@i32@*/ transferType)
+                       fileloc loc, transferKind transferType)
 {
   valueTable fvalues = sRef_getValueTable (fref);
   valueTable tvalues = sRef_getValueTable (tref);
@@ -4199,8 +4236,6 @@ checkMetaStateTransfer (exprNode fexp, sRef fref, exprNode texp, sRef tref,
              {
                if (nval == stateValue_error)
                  {
-                   /*@i32 print extra info for assignments@*/
-                   
                    if (optgenerror 
                        (FLG_STATETRANSFER,
                         message
@@ -4408,7 +4443,7 @@ static /*@exposed@*/ sRef
   return sRef_undefined;
 }
 
-bool canLoseReference (/*@dependent@*/ sRef sr, fileloc loc)
+bool transferChecks_canLoseReference (/*@dependent@*/ sRef sr, fileloc loc)
 {
   bool gotone = FALSE;
   sRefSet ab = usymtab_aliasedBy (sr); /* yes, really mean aliasedBy */
This page took 0.083875 seconds and 4 git commands to generate.