From c3be260484f4cd5a9fb6f9ebc503ae4cecca2252 Mon Sep 17 00:00:00 2001 From: evans1629 Date: Thu, 12 Dec 2002 17:21:08 +0000 Subject: [PATCH] Cleaned up code problems reported by make splintme. --- src/Headers/context.h | 12 +++---- src/Headers/cscanner.h | 4 +++ src/Headers/functionClauseList.h | 2 ++ src/Headers/functionConstraint.h | 6 ++++ src/cgrammar.c.der | 2 +- src/cgrammar.y | 2 +- src/context.c | 13 +++---- src/cppexp.c | 4 +-- src/cppmain.c | 4 --- src/flags.c | 62 ++++++++++++++++++++++---------- src/functionClauseList.c | 31 ++++++++-------- src/functionConstraint.c | 12 +++---- src/stateInfo.c | 1 + src/uentry.c | 2 +- 14 files changed, 89 insertions(+), 68 deletions(-) diff --git a/src/Headers/context.h b/src/Headers/context.h index 1e03aff..a69186d 100644 --- a/src/Headers/context.h +++ b/src/Headers/context.h @@ -336,10 +336,6 @@ extern int context_getBugsLimit (void) /*@*/ ; # define context_getBugsLimit() ((int)context_getValue(FLG_BUGSLIMIT)) /*drl 12/30/2001 these are some ugly functions that were added to facilitate struct annotations */ - - -extern bool hasInvariants (ctype p_ct); - /*drl 1/6/2001: I didn't think these functions were solid enough to include in the stable release of splint. I commented them out so that they won't break anything but didn't delete them because they will be fixed and included later @@ -353,12 +349,14 @@ extern bool hasInvariants (ctype p_ct); /* sRef fixSref (ctype p_ct, sRef p_base, sRef p_fix); */ -ctype context_setLastStruct (/*@returned@*/ ctype p_s) /*@modifies internalState@*/; -ctype context_getLastStruct (/*@returned@*/ /*ctype p_s*/) /*@modifies internalState@*/; +extern ctype context_setLastStruct (/*@returned@*/ ctype p_s) /*@modifies internalState@*/; +extern ctype context_getLastStruct (/*@returned@*/ /*ctype p_s*/) /*@modifies internalState@*/; /*drl added 2/4/2002*/ - bool context_inOldSytleScope(void); +extern bool context_inOldStyleScope (void) /*@*/ ; +extern void context_setGlobalStructInfo (ctype p_ct, constraintList p_list) /*@modifies internalState@*/ ; + # else # error "Multiple include" # endif diff --git a/src/Headers/cscanner.h b/src/Headers/cscanner.h index efc30c0..ef0106e 100644 --- a/src/Headers/cscanner.h +++ b/src/Headers/cscanner.h @@ -7,6 +7,7 @@ ** cscanner.h */ +/*@-declundef@*/ /* Don't always check cscanner.c */ extern /*@observer@*/ cstring cscanner_observeLastIdentifier (void) ; extern void cscanner_expectingMetaStateName (void) /*@modifies internalState@*/ ; extern void cscanner_clearExpectingMetaStateName (void) /*@modifies internalState@*/ ; @@ -18,6 +19,7 @@ extern void cscanner_swallowMacro (void) /*@modifies internalState, fileSystem@* # ifdef S_SPLINT_S +/*@-namechecks@*/ typedef struct yy_buffer_state *YY_BUFFER_STATE; extern /*@unused@*/ void yy_switch_to_buffer (YY_BUFFER_STATE); @@ -35,5 +37,7 @@ extern /*@unused@*/ char *yytext; extern /*@unused@*/ void yyerror (char *); extern /*@unused@*/ int yychar; extern /*@unused@*/ int yynerrs; +/*@=namechecks@*/ +/*@=declundef@*/ # endif diff --git a/src/Headers/functionClauseList.h b/src/Headers/functionClauseList.h index 471949b..21717fe 100644 --- a/src/Headers/functionClauseList.h +++ b/src/Headers/functionClauseList.h @@ -48,6 +48,8 @@ extern functionClauseList extern /*@unused@*/ /*@only@*/ cstring functionClauseList_unparse (functionClauseList p_s) ; extern void functionClauseList_free (/*@only@*/ functionClauseList p_s) ; +extern void functionClauseList_getImplictConstraints (functionClauseList p_s) /*@*/ ; + /*@constant int functionClauseListBASESIZE;@*/ # define functionClauseListBASESIZE MIDBASESIZE diff --git a/src/Headers/functionConstraint.h b/src/Headers/functionConstraint.h index 83035c6..546e102 100644 --- a/src/Headers/functionConstraint.h +++ b/src/Headers/functionConstraint.h @@ -29,6 +29,12 @@ struct s_functionConstraint { extern /*@falsewhennull@*/ bool functionConstraint_isDefined (functionConstraint) /*@*/ ; # define functionConstraint_isDefined(p_info) ((p_info) != NULL) +extern /*@falsewhennull@*/ bool functionConstraint_isBufferConstraint (/*@sef@*/ functionConstraint) /*@*/ ; +# define functionConstraint_isBufferConstraint(p_con) (((p_con) != NULL) && ((p_con)->kind == FCT_BUFFER)) + +extern void functionConstraint_addBufferConstraints (functionConstraint p_fc, /*@only@*/ constraintList) + /*@modifies p_fc@*/ ; + extern /*@nullwhentrue@*/ bool functionConstraint_isUndefined (functionConstraint) /*@*/ ; # define functionConstraint_isUndefined(p_info) ((p_info) == NULL) diff --git a/src/cgrammar.c.der b/src/cgrammar.c.der index 753c423..c9e81e6 100644 --- a/src/cgrammar.c.der +++ b/src/cgrammar.c.der @@ -4704,7 +4704,7 @@ case 397: { sRef_clearGlobalScopeSafe (); ; break;} case 398: -{ ctype ct; ct = declareStruct (yyvsp[-9].cname, yyvsp[-4].flist); setGlobalStructInfo(ct, yyvsp[0].conL); yyval.ctyp = ct; ; +{ ctype ct; ct = declareStruct (yyvsp[-9].cname, yyvsp[-4].flist); context_setGlobalStructInfo(ct, yyvsp[0].conL); yyval.ctyp = ct; ; break;} case 399: { sRef_setGlobalScopeSafe (); ; diff --git a/src/cgrammar.y b/src/cgrammar.y index 780c349..9869c86 100644 --- a/src/cgrammar.y +++ b/src/cgrammar.y @@ -1418,7 +1418,7 @@ suSpc structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); } TRBRACE optStructInvariant - { ctype ct; ct = declareStruct ($3, $8); setGlobalStructInfo(ct, $12); $$ = ct; } + { ctype ct; ct = declareStruct ($3, $8); context_setGlobalStructInfo(ct, $12); $$ = ct; } | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); } CreateStructInnerScope structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); } diff --git a/src/context.c b/src/context.c index 61e67c2..81d8ada 100644 --- a/src/context.c +++ b/src/context.c @@ -1875,12 +1875,9 @@ context_enterFunction (/*@exposed@*/ uentry e) sRef_enterFunctionScope (); } -bool context_inOldSytleScope(void) +bool context_inOldStyleScope(void) { - if (gc.kind == CX_OLDSTYLESCOPE) - return TRUE; - else - return FALSE; + return (gc.kind == CX_OLDSTYLESCOPE); } void @@ -4907,9 +4904,7 @@ struct sInfo { /*@unused@*/ struct getUe * t ; }; - -static struct sInfo globalStructInfo; - +/* unused: static struct sInfo globalStructInfo; */ /*drl 1/6/2001: I didn't think these functions were solid enough to include in the stable release of splint. I coomented them out so that they won't break anything @@ -4920,7 +4915,7 @@ static struct sInfo globalStructInfo; /*@-paramuse@*/ -void setGlobalStructInfo(ctype ct, constraintList list) +void context_setGlobalStructInfo(ctype ct, constraintList list) { # if 0 /* int i; diff --git a/src/cppexp.c b/src/cppexp.c index e79321e..588eaf1 100644 --- a/src/cppexp.c +++ b/src/cppexp.c @@ -153,7 +153,7 @@ Written by Per Bothner 1994. */ static struct operation cppexp_lex (cppReader *); static void integer_overflow (cppReader *); -static long left_shift (cppReader *, long, bool p_unsignedp, size_t); +static long left_shift (cppReader *, long, bool p_unsignedp, unsigned long); static long right_shift (long, bool p_unsignedp, unsigned long); /*@constant short CPPREADER_ERRORTOK@*/ @@ -798,7 +798,7 @@ integer_overflow (cppReader *pfile) } static long -left_shift (cppReader *pfile, long a, bool unsignedp, size_t b) +left_shift (cppReader *pfile, long a, bool unsignedp, unsigned long b) { if (b >= HOST_BITS_PER_LONG) { diff --git a/src/cppmain.c b/src/cppmain.c index 991ed85..36b1ce0 100644 --- a/src/cppmain.c +++ b/src/cppmain.c @@ -191,12 +191,8 @@ void cppAddIncludeDir (cstring dir) } else { - /* -I option (Add directory to include path) */ struct file_name_list *dirtmp = (struct file_name_list *) dmalloc (sizeof (*dirtmp)); - llassert (cstring_firstChar (dir) == 'I'); - dir = cstring_suffix (dir, 1); - DPRINTF (("Add include: %s", dir)); dirtmp->next = 0; /* New one goes on the end */ diff --git a/src/flags.c b/src/flags.c index d197f6c..cdc6dc7 100644 --- a/src/flags.c +++ b/src/flags.c @@ -1701,26 +1701,50 @@ flags_processFlags (bool inCommandLine, } else if (opt == FLG_INCLUDEPATH || opt == FLG_SPECPATH) { - cstring dir = cstring_suffix (cstring_fromChars (thisarg), 1); /* skip over I */ - - DPRINTF (("Directory: %s", dir)); - - switch (opt) - { - case FLG_INCLUDEPATH: - cppAddIncludeDir (dir); - /*@switchbreak@*/ break; - case FLG_SPECPATH: - /*@-mustfree@*/ - g_localSpecPath = cstring_toCharsSafe - (message ("%s%h%s", - cstring_fromChars (g_localSpecPath), - PATH_SEPARATOR, - dir)); - /*@=mustfree@*/ - /*@switchbreak@*/ break; - BADDEFAULT; + if (mstring_length (thisarg) < 2) { + BADBRANCH; + } else { + if (mstring_equal (thisarg, "-I-")) { + cppAddIncludeDir (cstring_fromChars (thisarg)); /* Need to handle this specially. */ + } else { + cstring dir = cstring_suffix (cstring_fromChars (thisarg), 2); /* skip over -I */ + + DPRINTF (("Length of thisarg [%s] %d", thisarg, cstring_length (thisarg))); + + if (cstring_length (dir) == 0) { + DPRINTF (("space after directory: ")); + if (++i < argc) { + dir = cstring_fromChars (argv[i]); + } else { + voptgenerror + (FLG_BADFLAG, + message + ("Flag %s must be followed by a directory name", + flagcode_unparse (opt)), + g_currentloc); + } + } + + DPRINTF (("Got directory: [%s]", dir)); + + switch (opt) + { + case FLG_INCLUDEPATH: + cppAddIncludeDir (dir); + /*@switchbreak@*/ break; + case FLG_SPECPATH: + /*@-mustfree@*/ + g_localSpecPath = cstring_toCharsSafe + (message ("%s%h%s", + cstring_fromChars (g_localSpecPath), + PATH_SEPARATOR, + dir)); + /*@=mustfree@*/ + /*@switchbreak@*/ break; + BADDEFAULT; + } } + } } else if (flagcode_isModeName (opt)) { diff --git a/src/functionClauseList.c b/src/functionClauseList.c index 9180f10..c05d8b0 100644 --- a/src/functionClauseList.c +++ b/src/functionClauseList.c @@ -173,39 +173,36 @@ functionClauseList_free (functionClauseList s) } void -functionClauseList_ImplictConstraints (functionClauseList s) +functionClauseList_getImplictConstraints (functionClauseList s) { functionClauseList_elements(s, el) { - if (functionClause_isRequires(el) ) + if (functionClause_isRequires(el)) { - functionConstraint con; - - con = functionClause_getRequires(el); - if (functionConstraint_hasBufferConstraint(con) ) + functionConstraint con = functionClause_getRequires(el); + + if (functionConstraint_hasBufferConstraint(con)) { - if (con->kind == FCT_BUFFER) + if (functionConstraint_isBufferConstraint (con)) { constraintList implCons = getImplicitFcnConstraints (); - - DPRINTF((message("functionClauseList_ImplictConstraints adding the implict constraints: %s to %s", - constraintList_print(implCons), constraintList_print( con->constraint.buffer) ) )); - con->constraint.buffer = constraintList_addList ( con->constraint.buffer, constraintList_copy(implCons)); - - DPRINTF((message("functionClauseList_ImplictConstraints the new constraint is %s", - constraintList_print( con->constraint.buffer) ) )); - + DPRINTF ((message ("functionClauseList_ImplictConstraints adding the implict constraints: %s to %s", + constraintList_print(implCons), constraintList_print (con->constraint.buffer)))); + functionConstraint_addBufferConstraints (con, constraintList_copy (implCons)); + + DPRINTF ((message ("functionClauseList_ImplictConstraints the new constraint is %s", + functionConstraint_unparse (con)))); } else { - llassert(FALSE); + llassert (FALSE); // fix this } } } } - + end_functionClauseList_elements } diff --git a/src/functionConstraint.c b/src/functionConstraint.c index 859434e..5a30602 100644 --- a/src/functionConstraint.c +++ b/src/functionConstraint.c @@ -219,11 +219,9 @@ extern void functionConstraint_free (/*@only@*/ functionConstraint node) } } - - - - - - - +void functionConstraint_addBufferConstraints (functionConstraint fc, constraintList clist) +{ + llassert (functionConstraint_isBufferConstraint (fc)); + fc->constraint.buffer = constraintList_addList (fc->constraint.buffer, clist); +} diff --git a/src/stateInfo.c b/src/stateInfo.c index 57bcdf6..7da32bb 100644 --- a/src/stateInfo.c +++ b/src/stateInfo.c @@ -53,6 +53,7 @@ void stateInfo_free (/*@only@*/ stateInfo a) else { stateInfo snew = stateInfo_makeRefLoc (newinfo->ref, newinfo->loc); + llassert (snew->previous == NULL); snew->previous = old; return snew; } diff --git a/src/uentry.c b/src/uentry.c index 1bf61d0..29277a3 100644 --- a/src/uentry.c +++ b/src/uentry.c @@ -11341,7 +11341,7 @@ void uentry_checkName (uentry ue) fileloc_free (tloc); uentry_setHasNameError (ue); - if (context_getFlag (FLG_REPEATUNRECOG) || (context_inOldSytleScope() ) ) + if (context_getFlag (FLG_REPEATUNRECOG) || (context_inOldStyleScope())) { uentry_markOwned (ue); } -- 2.45.1