]> andersk Git - splint.git/commitdiff
Fixed problem with loop guards in loop test effects. New test case
authorevans1629 <evans1629>
Sat, 16 Mar 2002 00:54:13 +0000 (00:54 +0000)
committerevans1629 <evans1629>
Sat, 16 Mar 2002 00:54:13 +0000 (00:54 +0000)
looptesteffect.  (Reported by Anders Pilegaard)

src/exprNode.c
src/fileTable.c
src/loopHeuristics.c
test/Makefile.am
test/Makefile.in
test/looptesteffect.c [new file with mode: 0644]
test/looptesteffect.expect [new file with mode: 0644]

index 1ecc6d60031378ec55391084bb84d6a7e020a695..ffdb4c0c4c4b802887cf8d2c58ff83f8c3b1dab4 100644 (file)
@@ -9076,9 +9076,47 @@ static /*@only@*/ exprNode exprNode_effect (exprNode e)
                                     exprNode_effect (exprData_getPairB (data)));
          break;
        case XPR_OP:
-         ret = exprNode_op (exprNode_effect (exprData_getOpA (data)), 
-                            exprNode_effect (exprData_getOpB (data)), 
-                            exprData_getOpTok (data));
+         /*
+         ** evans 2002-03-15: for && and ||, need to do the guards also
+         **                   this is what cgrammar.y does - should be
+         **                   able to avoid duplication, but need to
+         **                   time with grammar productions.
+         */
+
+         DPRINTF (("Effect: %s", exprNode_unparse (e)));
+
+         if (lltok_getTok (exprData_getOpTok (data)) == AND_OP)
+           {
+             exprNode e1 = exprNode_effect (exprData_getOpA (data));
+             exprNode e2;
+             exprNode_produceGuards (e1);
+             context_enterAndClause (e1);
+             e2 = exprNode_effect (exprData_getOpB (data));
+
+             ret = exprNode_op (e1, e2,
+                                exprData_getOpTok (data));
+
+             context_exitAndClause (ret, e2);
+           }
+         else if (lltok_getTok (exprData_getOpTok (data)) == OR_OP)
+           {
+             exprNode e1 = exprNode_effect (exprData_getOpA (data));
+             exprNode e2;
+             exprNode_produceGuards (e1);
+             context_enterOrClause (e1);
+             e2 = exprNode_effect (exprData_getOpB (data));
+
+             ret = exprNode_op (e1, e2,
+                                exprData_getOpTok (data));
+
+             context_exitOrClause (ret, e2);
+           }
+         else
+           {
+             ret = exprNode_op (exprNode_effect (exprData_getOpA (data)), 
+                                exprNode_effect (exprData_getOpB (data)), 
+                                exprData_getOpTok (data));
+           }
          break;
          
        case XPR_POSTOP:
index f33835ab2cf173e3823aee2e759fc8cf3892dae4..98daa02fe6fc6e52f4b9123148e1007be5d9dc70 100644 (file)
@@ -317,6 +317,17 @@ fileTable_addFilePrim (fileTable ft, /*@temp@*/ cstring name,
 
          e->basename = fileLib_removePathFree (fileLib_removeAnyExtension (absname));
          e->fsystem = context_isSystemDir (absname);
+
+         /*
+         ** evans 2002-03-15: change suggested by Jim Zelenka
+         **                   support relative paths for system directories
+         */
+
+         if (!e->fsystem)
+           {
+             e->fsystem = context_isSystemDir (name);
+           }
+
          e->fspecial = context_isSpecialFile (absname);
 
          if (e->fspecial)
index 4f7e46c90028daaa507e7cb2ef85a528d31d6f48..a0c857add3f55cc02d91756ee029c96a0378d5a7 100644 (file)
@@ -41,8 +41,6 @@
 # include "exprChecks.h"
 # include "exprNodeSList.h"
 
-# include "exprDataQuite.i"
-
 /*@access constraint, exprNode @*/  /* !!! NO! */
 
 /*@access constraintExpr @*/ /* !!! NO! */
index ebb22b6f92580f4d6e6dae37634c8b2cbe82e975..8b82f51d8178d36bcaa388439bf8c3c6fd501f19 100644 (file)
@@ -41,7 +41,7 @@ UNITTESTS = \
   compoundliterals compoundstmt constannot controldepth csyntax czechnames czechoslovaknames deadparam \
   decl divzero enum exports external fields flags forbody format freearray \
   funcpointer functionmacro glob globals impabstract info init inparam internal iter keep libs \
-  linked lintcomments list loopexec \
+  linked lintcomments list loopexec looptesteffect \
   macros macrosef merge mergenull modifies modtest moduncon \
   mongoincludes mystrncat noeffect null observer oldstyle outglob outparam \
   parentype postnotnull preds prefixes printflike rc refcounts release repexpose \
@@ -500,6 +500,9 @@ loopexec:
        -$(SPLINTR) loopexec.c -expect 1
        -$(SPLINTR) loopexec.c -obviousloopexec -expect 3
 
+.PHONY: looptesteffect
+looptesteffect:
+       -$(SPLINTR) looptesteffect.c -expect 1
 
 .PHONY: macros
 macros:
@@ -1510,11 +1513,11 @@ EXTRA_DIST =  ./abst_t.lcl ./abst_t.lcs  \
               ./moreBufferTests2/Makefile \
               ./fileio/eof.mts ./fileio/file.mts ./fileio/filerw.mts ./mergestate/tainted.mts ./mergestate/taintednm.mts ./metastate/file.mts ./metastate/nullterminated.mts ./metastate/sockets.mts ./tainted/tainted-bad.mts ./tainted/tainted.mts ./fileio/file.xh ./fileio/filerw.xh ./mergestate/tainted.xh ./mergestate/taintednm.xh ./metastate/file.xh ./tainted/tainted.xh \
                 db2.old-expect   union.pp warnuse.old-expect \
-               ./tests2.5/badcomment  ./tests2.5/boolbad  ./tests2.5/booltest   ./tests2.5/uconstants  loopexec.expect mergenull.expect shifts.expect \
+               ./tests2.5/badcomment  ./tests2.5/boolbad  ./tests2.5/booltest   ./tests2.5/uconstants  loopexec.expect mergenull.expect shifts.expect looptesteffect.expect \
                 unioninit.expect  unioninit.c utypes.c \
                 utypes.expect widestrings.expect  widestrings.c  \
                 functionmacro.expect functionmacro.c  info.c info.expect \
-                loopexec.c mergenull.c shifts.c \
+                loopexec.c looptesteffect.c mergenull.c shifts.c \
                 manual.expect ./manual/Makefile \
                 ./manual/annotglobs.c  ./manual/bool.c  ./manual/bool.h  ./manual/clauses.c  ./manual/employee.h  ./manual/exposure.c  ./manual/globals.c  ./manual/ignore.c  ./manual/implicit.c  ./manual/intSet.h  ./manual/list.c  ./manual/loop.c  ./manual/macros.c  ./manual/modify.c  ./manual/mstring.c  ./manual/mstring.h  ./manual/mstringnn.c  ./manual/multiError.c  ./manual/names.c  ./manual/noeffect.c  ./manual/null.c  ./manual/only.c  ./manual/order.c  ./manual/palindrome.c  ./manual/palindrome.h  ./manual/refs.c  ./manual/returned.c  ./manual/rgb.c  ./manual/rstring.c  ./manual/rstring.h  ./manual/sample.c  ./manual/setChar.c  ./manual/setname.c  ./manual/setname.h  ./manual/special.c  ./manual/stack.c  ./manual/sumsquares.c  ./manual/switch.c  ./manual/testpal.c  ./manual/types.c  ./manual/unique.c  ./manual/usedef.c  ./manual/bounds.c \
                   arraydims.expect arraydims.c \
index 1b157b94e273f1ccf39f56916b7e60e880c9d231..ac1b25d2484f350522cf96ad0a80045f69c7a88a 100644 (file)
@@ -118,7 +118,7 @@ UNITTESTS = \
   compoundliterals compoundstmt constannot controldepth csyntax czechnames czechoslovaknames deadparam \
   decl divzero enum exports external fields flags forbody format freearray \
   funcpointer functionmacro glob globals impabstract info init inparam internal iter keep libs \
-  linked lintcomments list loopexec \
+  linked lintcomments list loopexec looptesteffect \
   macros macrosef merge mergenull modifies modtest moduncon \
   mongoincludes mystrncat noeffect null observer oldstyle outglob outparam \
   parentype postnotnull preds prefixes printflike rc refcounts release repexpose \
@@ -768,11 +768,11 @@ EXTRA_DIST = ./abst_t.lcl ./abst_t.lcs  \
               ./moreBufferTests2/Makefile \
               ./fileio/eof.mts ./fileio/file.mts ./fileio/filerw.mts ./mergestate/tainted.mts ./mergestate/taintednm.mts ./metastate/file.mts ./metastate/nullterminated.mts ./metastate/sockets.mts ./tainted/tainted-bad.mts ./tainted/tainted.mts ./fileio/file.xh ./fileio/filerw.xh ./mergestate/tainted.xh ./mergestate/taintednm.xh ./metastate/file.xh ./tainted/tainted.xh \
                 db2.old-expect   union.pp warnuse.old-expect \
-               ./tests2.5/badcomment  ./tests2.5/boolbad  ./tests2.5/booltest   ./tests2.5/uconstants  loopexec.expect mergenull.expect shifts.expect \
+               ./tests2.5/badcomment  ./tests2.5/boolbad  ./tests2.5/booltest   ./tests2.5/uconstants  loopexec.expect mergenull.expect shifts.expect looptesteffect.expect \
                 unioninit.expect  unioninit.c utypes.c \
                 utypes.expect widestrings.expect  widestrings.c  \
                 functionmacro.expect functionmacro.c  info.c info.expect \
-                loopexec.c mergenull.c shifts.c \
+                loopexec.c looptesteffect.c mergenull.c shifts.c \
                 manual.expect ./manual/Makefile \
                 ./manual/annotglobs.c  ./manual/bool.c  ./manual/bool.h  ./manual/clauses.c  ./manual/employee.h  ./manual/exposure.c  ./manual/globals.c  ./manual/ignore.c  ./manual/implicit.c  ./manual/intSet.h  ./manual/list.c  ./manual/loop.c  ./manual/macros.c  ./manual/modify.c  ./manual/mstring.c  ./manual/mstring.h  ./manual/mstringnn.c  ./manual/multiError.c  ./manual/names.c  ./manual/noeffect.c  ./manual/null.c  ./manual/only.c  ./manual/order.c  ./manual/palindrome.c  ./manual/palindrome.h  ./manual/refs.c  ./manual/returned.c  ./manual/rgb.c  ./manual/rstring.c  ./manual/rstring.h  ./manual/sample.c  ./manual/setChar.c  ./manual/setname.c  ./manual/setname.h  ./manual/special.c  ./manual/stack.c  ./manual/sumsquares.c  ./manual/switch.c  ./manual/testpal.c  ./manual/types.c  ./manual/unique.c  ./manual/usedef.c  ./manual/bounds.c \
                   arraydims.expect arraydims.c \
@@ -1318,6 +1318,10 @@ loopexec:
        -$(SPLINTR) loopexec.c -expect 1
        -$(SPLINTR) loopexec.c -obviousloopexec -expect 3
 
+.PHONY: looptesteffect
+looptesteffect:
+       -$(SPLINTR) looptesteffect.c -expect 1
+
 .PHONY: macros
 macros:
        -$(SPLINTR) macros -expect 17 
diff --git a/test/looptesteffect.c b/test/looptesteffect.c
new file mode 100644 (file)
index 0000000..46ed290
--- /dev/null
@@ -0,0 +1,19 @@
+
+typedef struct elem_ elem;
+
+struct elem_ {
+  /*@null@*/ elem *next;
+  int val;
+};
+
+void foo(/*@null@*/ elem *e)
+{
+  if ((e != NULL) && (e->val > 2))
+    {
+      ;
+    }
+
+  for (; ((e != NULL) && (e->val > 2)); e=e->next) ;
+
+  for (; ((e == NULL) || (e->val > 2)); e=e->next) ;
+}
diff --git a/test/looptesteffect.expect b/test/looptesteffect.expect
new file mode 100644 (file)
index 0000000..01ddab9
--- /dev/null
@@ -0,0 +1,7 @@
+
+looptesteffect.c: (in function foo)
+looptesteffect.c:18:43: Arrow access from possibly null pointer e (in post loop
+                           increment): e->next
+   looptesteffect.c:18:43: Storage e may become null
+
+Finished checking --- 1 code warning, as expected
This page took 0.085003 seconds and 5 git commands to generate.