From 57c5e0be3a6c9e7c319048510da442cb4898f60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Oct 2016 14:16:08 +0200 Subject: [PATCH] test that abs,isdigit,strlen are calculated properly --- test/cfg/std.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/cfg/std.c b/test/cfg/std.c index 47abe4f3b..b3cde936a 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -3684,3 +3684,26 @@ void invalidPrintfArgType_printf(void) // cppcheck-suppress invalidPrintfArgType_uint printf("%"PRIi16"\n", n); } + + +#define AssertAlwaysTrue(C) if (C) {} + +void valueFlow(void) +{ + const char abc[] = "abc"; + int three = 3, minusThree = -3; + int c0='0', ca='a'; + + // When adding functions below, please sort alphabetically. + + // cppcheck-suppress knownConditionTrueFalse + AssertAlwaysTrue(strlen(abc) == 3); + // cppcheck-suppress knownConditionTrueFalse + AssertAlwaysTrue(abs(three) == 3); + // cppcheck-suppress knownConditionTrueFalse + AssertAlwaysTrue(abs(minusThree) == 3); + // cppcheck-suppress knownConditionTrueFalse + AssertAlwaysTrue(isdigit(c0) == 1); + // cppcheck-suppress knownConditionTrueFalse + AssertAlwaysTrue(isdigit(ca) == 0); +}