Skip to content

Commit d1d6247

Browse files
fixup! fixup! fixup! fixup! fixup! fixup! Fix #1473: warn when fclose() is used as a while loop condition
1 parent c4cbabc commit d1d6247

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

lib/checkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ void CheckIO::fcloseInLoopConditionError(const Token *tok, const std::string &va
418418
{
419419
reportError(tok, Severity::warning,
420420
"fcloseInLoopCondition",
421-
"fclose() should not be used as a loop condition.\n"
421+
"fclose() used as loop condition may skip loop body or double-close file handle.\n"
422422
"fclose() closes '" + varname + "' each time it is evaluated. On success the loop body might never execute, on failure fclose() might be called again on the already-closed file handle.",
423423
CWE910, Certainty::normal);
424424
}

test/testio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ class TestIO : public TestFixture {
544544
" FILE *a = fopen(\"aa\", \"r\");\n"
545545
" while (fclose(a)) {}\n"
546546
"}");
547-
ASSERT_EQUALS("[test.cpp:3:12]: (warning) fclose() should not be used as a loop condition. [fcloseInLoopCondition]\n", errout_str());
547+
ASSERT_EQUALS("[test.cpp:3:12]: (warning) fclose() used as loop condition may skip loop body or double-close file handle. [fcloseInLoopCondition]\n", errout_str());
548548

549549
check("void foo() {\n"
550550
" FILE *a = fopen(\"aa\", \"r\");\n"
@@ -566,7 +566,7 @@ class TestIO : public TestFixture {
566566
" FILE *a = fopen(\"aa\", \"r\");\n"
567567
" do {} while (fclose(a));\n"
568568
"}");
569-
ASSERT_EQUALS("[test.cpp:3:18]: (warning) fclose() should not be used as a loop condition. [fcloseInLoopCondition]\n", errout_str());
569+
ASSERT_EQUALS("[test.cpp:3:18]: (warning) fclose() used as loop condition may skip loop body or double-close file handle. [fcloseInLoopCondition]\n", errout_str());
570570

571571
// #6823
572572
check("void foo() {\n"

0 commit comments

Comments
 (0)