Correspond to error messages for constraints that have only constants.
/*drl 1/6/2001: I didn't think these functions were solid enough to include in the stable release of splint.*/
/*drl added 12/30/01 */
/* extern / *@only@* / constraint constraint_doSRefFixInvarConstraint(constraint p_invar, sRef p_s, ctype p_ct ); */
-
+
+/*drl added 12/19 */
+bool constraint_isConstantOnly (constraint p_c);
/*@=czechfcns*/
/* drl possible problem : warning take this out */
/* drl added 12/30/001*/
/* extern / *@only@* / constraintExpr constraintExpr_doSRefFixInvarConstraint (/ *@only@* / constraintExpr p_expr, sRef p_s, ctype p_ct); */
-
+
+
+/*drl added 12/19 */
+bool constraintExpr_isConstantOnly ( constraintExpr p_e );
+
#else
# error "Multiple include"
#endif
/*@=namechecks@*/
+/*drl added 12/19/2002*/
+bool constraintTerm_isConstantOnly ( constraintTerm p_term );
+
#else
#error Multiple Include
## Non-built files we need to distribute
EXTRA_DIST = $(BISON_SRC) bison.head bison.reset $(HEADERSRC) \
flags.def cscanner.l flex.head flex.reset $(IFILES) \
+ .splintrc LICENSE \
+ Headers/cscannerHelp.h \
Headers/256_random_numbers.nf Headers/splintMacros.nf Headers/reservedNames.nf
#Makefile.binary.am Makefile.binary.in
EXTRA_DIST = $(BISON_SRC) bison.head bison.reset $(HEADERSRC) \
flags.def cscanner.l flex.head flex.reset $(IFILES) \
+ .splintrc LICENSE \
+ Headers/cscannerHelp.h \
Headers/256_random_numbers.nf Headers/splintMacros.nf Headers/reservedNames.nf
#Makefile.binary.am Makefile.binary.in
cstring string;
fileloc errorLoc, temp;
+ bool isLikely;
/*drl 11/26/2001 avoid printing tautological constraints */
if (constraint_isAlwaysTrue (c))
string = cstring_replaceChar(string, '\n', ' ');
}
+ /*drl added 12/19/2002 print
+ a different error fro "likely" bounds-errors*/
+
+ isLikely = constraint_isConstantOnly(c);
- if (c->post)
+ if (isLikely)
+ {
+ if (c->post)
+ {
+ voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
+ }
+ else
+ {
+ if (constraint_hasMaxSet (c))
+ {
+ voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
+ }
+ else
+ {
+ voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
+ }
+ }
+ }
+ else if (c->post)
{
voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
}
cstring st = cstring_undefined;
cstring temp = cstring_undefined;
cstring genExpr;
+ bool isLikely;
if (!c->post)
{
st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_printDeep (c));
}
- if (constraint_hasMaxSet (c))
+ isLikely = constraint_isConstantOnly(c);
+
+ if (isLikely)
{
- temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
+ if (constraint_hasMaxSet (c))
+ {
+ temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
+ }
+ else
+ {
+ temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
+ }
}
else
{
- temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
+
+ if (constraint_hasMaxSet (c))
+ {
+ temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
+ }
+ else
+ {
+ temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
+ }
}
genExpr = exprNode_unparse (c->generatingExpr);
return FALSE;
}
+
+/*drl added 12/19/2002*/
+/*whether constraints consist only of
+ terms which are constants*/
+bool constraint_isConstantOnly (constraint c)
+{
+ bool l, r;
+
+ l = constraintExpr_isConstantOnly(c->lexpr);
+ r = constraintExpr_isConstantOnly(c->expr);
+
+ if (l && r)
+ {
+ return TRUE;
+ }
+
+ else
+ {
+ return FALSE;
+ }
+
+}
return e;
}
+
+bool constraintExpr_isConstantOnly ( constraintExpr e )
+{
+ DPRINTF(( (message("constraintExpr_isConstantOnly %s ",
+ constraintExpr_unparse(e) ) )
+ ));
+
+ switch (e->kind)
+ {
+ case term:
+ {
+ constraintTerm t;
+
+ t = constraintExprData_termGetTerm(e->data);
+
+
+ if (constraintTerm_isConstantOnly (t) )
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
+ case binaryexpr:
+ {
+ constraintExpr temp1, temp2;
+
+ temp1 = constraintExprData_binaryExprGetExpr1 (e->data);
+
+ temp2 = constraintExprData_binaryExprGetExpr2 (e->data);
+
+ if (constraintExpr_isConstantOnly(temp1) &&
+ constraintExpr_isConstantOnly(temp2) )
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
+ case unaryExpr:
+ {
+ constraintExpr temp;
+
+ temp = constraintExprData_unaryExprGetExpr (e->data );
+
+ if (constraintExpr_isConstantOnly(temp) )
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ default:
+ BADEXIT;
+ }
+}
+
return ct;
}
+bool constraintTerm_isConstantOnly (constraintTerm term)
+{
+ switch (term->kind)
+ {
+ case EXPRNODE:
+ if (exprNode_isNumLiteral (term->value.expr) ||
+ exprNode_isStringLiteral (term->value.expr) ||
+ exprNode_isCharLiteral (term->value.expr) )
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+
+ case INTLITERAL:
+ return TRUE;
+
+ case SREF:
+ if ( sRef_isConst (term->value.sref) )
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ default:
+ BADEXIT;
+ }
+
+ BADEXIT;
+}
DOSET (FLG_ALLMACROS, b);
DOSET (FLG_FCNMACROS, b);
DOSET (FLG_CONSTMACROS, b);
- break;
+ break;
case FLG_BOUNDS:
DOSET (FLG_BOUNDSREAD, b);
DOSET (FLG_BOUNDSWRITE, b);
+ DOSET (FLG_LIKELYBOUNDSREAD, b);
+ DOSET (FLG_LIKELYBOUNDSWRITE, b);
+ break;
+ case FLG_BOUNDSREAD:
+ DOSET (FLG_LIKELYBOUNDSREAD, b);
+ break;
+ case FLG_BOUNDSWRITE:
+ DOSET (FLG_LIKELYBOUNDSWRITE, b);
break;
+ case FLG_LIKELYBOUNDS:
+ DOSET (FLG_LIKELYBOUNDSREAD, b);
+ DOSET (FLG_LIKELYBOUNDSWRITE, b);
+ break;
+
case FLG_CZECH:
if (b) { DOSET (FLG_ACCESSCZECH, b); }
DOSET (FLG_CZECHFUNCTIONS, b);
/* check if errors will printed */
if (!(context_getFlag(FLG_DEBUGFUNCTIONCONSTRAINT) ||
context_getFlag(FLG_BOUNDSWRITE) ||
- context_getFlag(FLG_BOUNDSREAD) ||
- context_getFlag(FLG_CHECKPOST)))
+ context_getFlag(FLG_BOUNDSREAD) ||
+ context_getFlag(FLG_LIKELYBOUNDSWRITE) ||
+ context_getFlag(FLG_LIKELYBOUNDSREAD) ||
+ context_getFlag(FLG_CHECKPOST) ))
{
exprNode_free (body);
context_exitInnerPlain();
"memory bounds checking (sets boundsread and boundswrite)",
"Memory read or write may be out of bounds of allocated storage.", 0, 0
},
+ {
+ FK_BOUNDS, FK_MEMORY, specialFlag,
+ "likelybounds",
+ FLG_LIKELYBOUNDS,
+ "memory bounds checking (sets likelyboundsread and likelyboundswrite)",
+ "Memory read or write may be out of bounds of allocated storage.", 0, 0
+ },
+ {
+ FK_BOUNDS, FK_MEMORY, plainFlag,
+ "likely-boundsread",
+ FLG_LIKELYBOUNDSREAD,
+ "likely out of bounds read",
+ "A memory read references memory beyond the allocated storage.",
+ 0, 0
+ },
+ {
+ FK_BOUNDS, FK_MEMORY, plainFlag,
+ "likely-boundswrite",
+ FLG_LIKELYBOUNDSWRITE,
+ "likely buffer overflow from an out of bounds write",
+ "A memory write may write to an address beyond the allocated buffer.",
+ 0, 0
+ },
+
{
FK_BOUNDS, FK_MEMORY, plainFlag,
"boundsread",
needed to satisfy precondition:
requires maxSet(str @ constannot.c:11:3) >= 20
constannot.c: (in function foo3)
-constannot.c:20:3: Possible out-of-bounds store:
+constannot.c:20:3: Likely out-of-bounds store:
foo(buf)
Unable to resolve constraint:
requires <const int=20> <= 19
Finished checking --- 1 code warning, as expected
-setChar.c:5: Possible out-of-bounds store:
+setChar.c:5: Likely out-of-bounds store:
buf[10]
Unable to resolve constraint:
requires 9 >= 10
m.c:9:1: Index of possibly null pointer f: f
m.c:8:5: Storage f may become null
sizeof.c: (in function f)
-sizeof.c:17:1: Possible out-of-bounds store:
+sizeof.c:17:1: Likely out-of-bounds store:
x[(sizeof(x))]
Unable to resolve constraint:
requires 2 >= 3
test3.c:2:6: Function t defined more than once
m.c:11:1: Previous definition of t
test3.c: (in function t)
-test3.c:9:3: Possible out-of-bounds store:
+test3.c:9:3: Likely out-of-bounds store:
g[101]
Unable to resolve constraint:
requires 99 >= 101
sizeof.c: (in function main)
-sizeof.c:6:2: Possible out-of-bounds store:
+sizeof.c:6:2: Likely out-of-bounds store:
x[(sizeof(x))]
Unable to resolve constraint:
requires 2 >= 3