From: evans1629 Date: Sat, 16 Mar 2002 00:54:13 +0000 (+0000) Subject: Fixed problem with loop guards in loop test effects. New test case X-Git-Tag: splint-3_1_0~134 X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/commitdiff_plain/52e90c0f77bb0e3edb043873b71a73459d4ae8ab Fixed problem with loop guards in loop test effects. New test case looptesteffect. (Reported by Anders Pilegaard) --- diff --git a/src/exprNode.c b/src/exprNode.c index 1ecc6d6..ffdb4c0 100644 --- a/src/exprNode.c +++ b/src/exprNode.c @@ -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: diff --git a/src/fileTable.c b/src/fileTable.c index f33835a..98daa02 100644 --- a/src/fileTable.c +++ b/src/fileTable.c @@ -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) diff --git a/src/loopHeuristics.c b/src/loopHeuristics.c index 4f7e46c..a0c857a 100644 --- a/src/loopHeuristics.c +++ b/src/loopHeuristics.c @@ -41,8 +41,6 @@ # include "exprChecks.h" # include "exprNodeSList.h" -# include "exprDataQuite.i" - /*@access constraint, exprNode @*/ /* !!! NO! */ /*@access constraintExpr @*/ /* !!! NO! */ diff --git a/test/Makefile.am b/test/Makefile.am index ebb22b6..8b82f51 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 \ diff --git a/test/Makefile.in b/test/Makefile.in index 1b157b9..ac1b25d 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -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 index 0000000..46ed290 --- /dev/null +++ b/test/looptesteffect.c @@ -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 index 0000000..01ddab9 --- /dev/null +++ b/test/looptesteffect.expect @@ -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