From: evans1629 Date: Wed, 5 Nov 2003 14:42:41 +0000 (+0000) Subject: Added realrelatecompare flag. X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/commitdiff_plain/419f7a7a4b388dfc03c75bebaffcf97116ea0410 Added realrelatecompare flag. --- diff --git a/src/context.c b/src/context.c index 0f1906b..f3e0290 100644 --- a/src/context.c +++ b/src/context.c @@ -850,7 +850,7 @@ context_resetAllFlags (void) gc.flags[FLG_NUMLITERAL] = TRUE; gc.flags[FLG_DUPLICATEQUALS] = TRUE; gc.flags[FLG_SKIPISOHEADERS] = TRUE; - gc.flags[FLG_SKIPPOSIXHEADERS] = TRUE; + gc.flags[FLG_SKIPPOSIXHEADERS] = FALSE; gc.flags[FLG_SYSTEMDIREXPAND] = TRUE; gc.flags[FLG_UNRECOGCOMMENTS] = TRUE; gc.flags[FLG_UNRECOGFLAGCOMMENTS] = TRUE; @@ -1235,7 +1235,7 @@ context_setModeAux (cstring s, bool warn) FLG_CHECKSTRICTGLOBALS, FLG_IMPCHECKEDSPECGLOBALS, FLG_MACROMATCHNAME, FLG_WARNLINTCOMMENTS, FLG_INCLUDENEST, FLG_ISORESERVED, FLG_CPPNAMES, - FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE, + FLG_NOPARAMS, FLG_IFEMPTY, FLG_WHILEEMPTY, FLG_REALCOMPARE, FLG_REALRELATECOMPARE, FLG_BOOLOPS, FLG_SHIFTNEGATIVE, FLG_SHIFTIMPLEMENTATION, FLG_BUFFEROVERFLOWHIGH, FLG_BUFFEROVERFLOW, @@ -1371,7 +1371,7 @@ context_setModeAux (cstring s, bool warn) FLG_FOREMPTY, FLG_WHILEEMPTY, FLG_IFEMPTY, FLG_IFBLOCK, FLG_ELSEIFCOMPLETE, - FLG_REALCOMPARE, FLG_BOOLOPS, + FLG_REALCOMPARE, FLG_BOOLOPS, FLG_REALRELATECOMPARE, FLG_SYSTEMDIRERRORS, FLG_UNUSEDSPECIAL, FLG_SHIFTNEGATIVE, diff --git a/src/cpplib.c b/src/cpplib.c index 5aff1e9..4b4e162 100644 --- a/src/cpplib.c +++ b/src/cpplib.c @@ -6210,6 +6210,8 @@ get_next: if (cc == '\n') { /* Backslash newline is replaced by nothing at all. */ + pfile->lineno++; /* 2003-11-03: AMiller suggested adding this, but + its not clear why it is needed. */ cppReader_adjustWritten (pfile, -1); pfile->lineno++; } diff --git a/src/exprNode.c b/src/exprNode.c index dca9548..9ddccbe 100644 --- a/src/exprNode.c +++ b/src/exprNode.c @@ -5829,12 +5829,24 @@ exprNode_makeOp (/*@keep@*/ exprNode e1, /*@keep@*/ exprNode e2, } else { - voptgenerror - (FLG_REALCOMPARE, - message ("Dangerous comparison involving %s types: %s", - ctype_unparse (rtype), - exprNode_unparse (ret)), - ret->loc); + if (opid == EQ_OP || opid == NE_OP) + { + voptgenerror + (FLG_REALCOMPARE, + message ("Dangerous equality comparison involving %s types: %s", + ctype_unparse (rtype), + exprNode_unparse (ret)), + ret->loc); + } + else + { + voptgenerror + (FLG_REALRELATECOMPARE, + message ("Possibly dangerous relational comparison involving %s types: %s", + ctype_unparse (rtype), + exprNode_unparse (ret)), + ret->loc); + } } } /*@fallthrough@*/ diff --git a/src/flags.def b/src/flags.def index e210f93..6b616e6 100644 --- a/src/flags.def +++ b/src/flags.def @@ -248,10 +248,23 @@ static flaglist flags = FK_OPS, FK_NONE, modeFlag, "realcompare", FLG_REALCOMPARE, - "dangerous comparison between reals (dangerous because of inexact " + "dangerous equality comparison between reals (dangerous because of inexact " "floating point representations)", "Two real (float, double, or long double) values are compared " - "directly using a C primitive. " + "directly using == or != primitive. " + "This may produce unexpected results since floating point " + "representations are inexact. Instead, compare the difference to " + "FLT_EPSILON or DBL_EPSILON.", + 0, 0, + }, + { + FK_OPS, FK_NONE, modeFlag, + "realrelatecompare", + FLG_REALRELATECOMPARE, + "possibly dangerous relational comparison between reals (dangerous because of inexact " + "floating point representations)", + "Two real (float, double, or long double) values are compared " + "directly using < or >. " "This may produce unexpected results since floating point " "representations are inexact. Instead, compare the difference to " "FLT_EPSILON or DBL_EPSILON.", diff --git a/test/info.expect b/test/info.expect index 31b8bbc..676c8b7 100644 --- a/test/info.expect +++ b/test/info.expect @@ -4,8 +4,8 @@ info.c:3:3: Unrecognized identifier: i info.c:6:57: Unrecognized pre-processor directive: #info "LcLint ignores all code that follows this line!" info.c: (in function unhuppy_bug) -info.c:9:3: Observer storage assigned to unqualified reference: i = "Asdf" - info.c:9:7: Storage becomes observer +info.c:10:3: Observer storage assigned to unqualified reference: i = "Asdf" + info.c:10:7: Storage becomes observer info.c:1:13: File static function huppy_bug declared but not used info.c:4:1: Definition of huppy_bug