]> andersk Git - splint.git/blobdiff - src/transferChecks.c
Fixed problem with NULL being changed.
[splint.git] / src / transferChecks.c
index 30f9a98d446bffd97258c7c34079afe36b8c8ad8..4fe2247ba761a3ec75c851f6ee8ec6dc1ed3103c 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** 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,8 +17,8 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on splint: splint@cs.virginia.edu
-** To report a bug: splint-bug@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
 */
 /*
@@ -505,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 */
            }
@@ -775,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);
        }
@@ -1655,7 +1657,7 @@ transferChecks_return (exprNode fexp, uentry rval)
     {
       if (stateClause_isGlobal (cl))
        {
-         ; /*@i32@*/
+         ; 
        }
       else if (stateClause_setsMetaState (cl))
        {
@@ -1693,7 +1695,6 @@ transferChecks_return (exprNode fexp, uentry rval)
                           exprNode_loc (fexp)))
                        {
                          sRef_showAliasInfo (sr); 
-                         /*@i32@*/
                        }
                    }
                }
@@ -1722,7 +1723,8 @@ transferChecks_return (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);
                  
@@ -2234,7 +2236,10 @@ transferChecks_passParam (exprNode fexp, uentry arg, bool isSpec,
          sRef_clearDerived (base);
          sRef_setDefined (base, exprNode_loc (fexp));
          usymtab_clearAlias (base);
-         sRef_setNullUnknown (base, exprNode_loc (fexp));
+         /* evans 2004-07-31: Don't change state of constants! */
+         if (!sRef_isConst (base)) {
+           sRef_setNullUnknown (base, exprNode_loc (fexp));
+         }
        }
     }
 
@@ -2344,7 +2349,7 @@ static void checkStructTransfer (exprNode lhs, sRef slhs, exprNode rhs, sRef srh
   if (ctype_isSU (st) && ctype_isRealSU (sRef_getType (slhs))
       && ctype_match (sRef_getType (slhs), st))
     {
-      if (tt == TT_DOASSIGN && sRef_isStateDefined (srhs))
+      if ((tt == TT_DOASSIGN || tt == TT_FIELDASSIGN) && sRef_isStateDefined (srhs))
        {
          sRef_setDefinedComplete (slhs, loc);
        }
@@ -2360,47 +2365,52 @@ static void checkStructTransfer (exprNode lhs, sRef slhs, exprNode rhs, sRef srh
          if (sRef_isLocalVar (slhs)
              && sRef_isFileOrGlobalScope (sRef_getRootBase (srhs)))
            {
+             DPRINTF (("Global scope!"));
              sRef_setDependent (slhs, exprNode_loc (lhs));
            }
-         else
-           {
-             if (ctype_isUnion (st))
-               {
-                 sRef_setDefState (slhs, sRef_getDefState (srhs), 
-                                   exprNode_loc (lhs));
+       }
 
-                 sRefSet_realElements (sRef_derivedFields (srhs), sr)
-                   {
-                     if (sRef_isField (sr))
-                       {
-                         cstring fieldname = sRef_getField (sr);
-                         sRef lfld = sRef_makeField (slhs, fieldname);
+      /*
+      ** evans 2003-07-10: should always copy the fields!
+      */
 
-                         (void) checkTransfer (rhs, sr, lhs, lfld, 
-                                               exprNode_undefined,
-                                               exprNode_loc (lhs), tt);
-                       }
-                   } end_sRefSet_realElements ;
-               }
-             else
+      if (ctype_isUnion (st))
+       {
+         sRef_setDefState (slhs, sRef_getDefState (srhs), 
+                           exprNode_loc (lhs));
+         
+         sRefSet_realElements (sRef_derivedFields (srhs), sr)
+           {
+             if (sRef_isField (sr))
                {
-                 uentryList fields = ctype_getFields (st);
+                 cstring fieldname = sRef_getField (sr);
+                 sRef lfld = sRef_makeField (slhs, fieldname);
                  
-                 uentryList_elements (fields, field)
-                   {
-                     sRef rfld = sRef_makeField (srhs, uentry_rawName (field));
-                     sRef lfld = sRef_makeField (slhs, uentry_rawName (field));
-                     (void) checkTransfer (rhs, rfld, lhs, lfld, 
-                                           exprNode_undefined,
-                                           exprNode_loc (lhs), tt);
-                   } end_uentryList_elements ;
-               }
-
-             if (sRef_isOnly (srhs))
-               {
-                 sRef_setKeptComplete (srhs, loc);
+                 (void) checkTransfer (rhs, sr, lhs, lfld, 
+                                       exprNode_undefined,
+                                       exprNode_loc (lhs), tt);
                }
-           }
+           } end_sRefSet_realElements ;
+       }
+      else
+       {
+         uentryList fields = ctype_getFields (st);
+         
+         uentryList_elements (fields, field)
+           {
+             sRef rfld = sRef_makeField (srhs, uentry_rawName (field));
+             sRef lfld = sRef_makeField (slhs, uentry_rawName (field));
+             DPRINTF (("Transfer field: %s := %s", 
+                       sRef_unparse (lfld), sRef_unparse (rfld)));
+             (void) checkTransfer (rhs, rfld, lhs, lfld, 
+                                   exprNode_undefined,
+                                   exprNode_loc (lhs), tt);
+           } end_uentryList_elements ;
+       }
+      
+      if (sRef_isOnly (srhs))
+       {
+         sRef_setKeptComplete (srhs, loc);
        }
     }
 }
@@ -2438,6 +2448,8 @@ transferChecks_assign (exprNode lhs, exprNode rhs)
 
   if (ctype_isRealSU (sRef_getType (srhs)))
     {
+      DPRINTF (("Check struct transfer: %s := %s", exprNode_unparse (lhs),
+               exprNode_unparse (rhs)));
       checkStructTransfer (lhs, slhs, rhs, srhs, exprNode_loc (lhs), TT_FIELDASSIGN);
     }
   else
@@ -2495,6 +2507,8 @@ checkTransferNullAux (sRef fref, exprNode fexp, /*@unused@*/ bool ffix,
   alkind tkind = sRef_getAliasKind (tref);
   ctype ttyp = ctype_realType (sRef_getType (tref));
 
+  DPRINTF (("Null transfer: %s => %s", sRef_unparseFull (fref), sRef_unparseFull (tref)));
+
   if (ctype_isUnknown (ttyp))
     {
       ttyp = exprNode_getType (texp);
@@ -2532,7 +2546,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),
@@ -2748,6 +2762,8 @@ checkTransferAssignAux (sRef fref, exprNode fexp, /*@unused@*/ bool ffix,
            }
        }
     }
+
+  DPRINTF (("Transfer ==> %s", sRef_unparseFull (tref)));
 }
 
 /*
@@ -3408,6 +3424,12 @@ checkTransferAux (exprNode fexp, /*@exposed@*/ sRef fref, bool ffix,
   bool isfcnpass = (transferType == TT_FCNPASS);
   bool isfcnreturn = (transferType == TT_FCNRETURN);
 
+  DPRINTF (("Check transfer: %s [%s] => %s [%s]",
+           exprNode_unparse (fexp),
+           sRef_unparseFull (fref),
+           exprNode_unparse (texp),
+           sRef_unparseFull (tref)));
+
   setCodePoint ();
 
   if (!ffix && !tfix)
@@ -3415,6 +3437,7 @@ checkTransferAux (exprNode fexp, /*@exposed@*/ sRef fref, bool ffix,
       setCodePoint ();
       checkTransferNullAux (fref, fexp, ffix, tref, texp, tfix, 
                            loc, transferType);
+      DPRINTF (("Transfer ==> %s", sRef_unparseFull (fref)));
     }
 
   if (isassign)
@@ -3422,6 +3445,7 @@ checkTransferAux (exprNode fexp, /*@exposed@*/ sRef fref, bool ffix,
       setCodePoint ();
       checkTransferAssignAux (fref, fexp, ffix, tref, texp, tfix,
                              loc, transferType);
+      DPRINTF (("Transfer ==> %s", sRef_unparseFull (fref)));
     }
 
   /*
@@ -3973,6 +3997,8 @@ checkTransferAux (exprNode fexp, /*@exposed@*/ sRef fref, bool ffix,
       ;
     }
 
+  DPRINTF (("Transfer ==> %s", sRef_unparseFull (fref)));
+  DPRINTF (("Transfer ==> %s", sRef_unparseFull (tref)));
   setCodePoint ();
 }
 
@@ -4015,7 +4041,6 @@ checkMetaStateConsistent (/*@exposed@*/ sRef fref, sRef tref,
          }
        else
          {
-           /*@i#!@!!@*/
            DPRINTF (("Cannot find meta state for: %s / to: %s / %s", sRef_unparseFull (fref),
                      sRef_unparseFull (tref),
                      fkey));
@@ -4136,7 +4161,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);
@@ -4174,7 +4199,6 @@ checkMetaStateTransfer (exprNode fexp, sRef fref, exprNode texp, sRef tref,
          }
        else
          {
-           /*@i#!@!!@*/
            DPRINTF (("Metastate transfer: %s => %s",
                      exprNode_unparse (fexp), exprNode_unparse (texp)));
            DPRINTF (("Cannot find meta state for: %s / to: %s / %s", sRef_unparseFull (fref),
@@ -4234,8 +4258,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
@@ -4447,7 +4469,9 @@ bool transferChecks_canLoseReference (/*@dependent@*/ sRef sr, fileloc loc)
 {
   bool gotone = FALSE;
   sRefSet ab = usymtab_aliasedBy (sr); /* yes, really mean aliasedBy */
-    
+
+  DPRINTF (("Aliased by: %s", sRefSet_unparse (ab)));
+
   /*
   ** if there is a local variable that aliases sr, then there is no
   ** error.  Make the local an only.
This page took 0.088073 seconds and 4 git commands to generate.