From 12b4bf75e07ef9911f7e45baf733e96b18d005b2 Mon Sep 17 00:00:00 2001 From: Martin Ettl Date: Wed, 30 Sep 2015 13:10:31 +0200 Subject: [PATCH] std.cfg: Fixed false negatives regarding uninitialized variable usage and added test cases. --- cfg/std.cfg | 6 ++++++ test/cfg/std.c | 44 ++++++++++++++++++++++++++++++++++++++++---- test/cfg/std.cpp | 44 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index cf62510df..4572ab6f6 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -3087,6 +3087,7 @@ + 0: @@ -3098,12 +3099,15 @@ + + + 0: @@ -3123,6 +3127,7 @@ + 0: @@ -3142,6 +3147,7 @@ + 0: diff --git a/test/cfg/std.c b/test/cfg/std.c index 05b29f00f..618a1985e 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -2975,40 +2975,76 @@ void uninivar_strpbrk(void) (void)strpbrk(cs,ct); } -void uninivar_strncat(void) +void uninivar_strncat(char *Ct, char *S, size_t N) { char *ct; char *s; size_t n; // cppcheck-suppress uninitvar (void)strncat(ct,s,n); + // cppcheck-suppress uninitvar + (void)strncat(ct,S,N); + // cppcheck-suppress uninitvar + (void)strncat(Ct,s,N); + // cppcheck-suppress uninitvar + (void)strncat(Ct,S,n); + + // no warning is expected for + (void)strncat(Ct,S,N); } -void uninivar_wcsncat(void) +void uninivar_wcsncat(wchar_t *Ct, wchar_t *S, size_t N) { wchar_t *ct; wchar_t *s; size_t n; // cppcheck-suppress uninitvar (void)wcsncat(ct,s,n); + // cppcheck-suppress uninitvar + (void)wcsncat(ct,S,N); + // cppcheck-suppress uninitvar + (void)wcsncat(Ct,s,N); + // cppcheck-suppress uninitvar + (void)wcsncat(Ct,S,n); + + // no warning is expected for + (void)wcsncat(Ct,S,N); } -void uninivar_strncmp(void) +void uninivar_strncmp(char *Ct, char *S, size_t N) { char *ct; char *s; size_t n; // cppcheck-suppress uninitvar (void)strncmp(ct,s,n); + // cppcheck-suppress uninitvar + (void)strncmp(ct,S,N); + // cppcheck-suppress uninitvar + (void)strncmp(Ct,s,N); + // cppcheck-suppress uninitvar + (void)strncmp(Ct,S,n); + + // no warning is expected for + (void)strncmp(Ct,S,N); } -void uninivar_wcsncmp(void) +void uninivar_wcsncmp(wchar_t *Ct, wchar_t *S, size_t N) { wchar_t *ct; wchar_t *s; size_t n; // cppcheck-suppress uninitvar (void)wcsncmp(ct,s,n); + // cppcheck-suppress uninitvar + (void)wcsncmp(ct,S,N); + // cppcheck-suppress uninitvar + (void)wcsncmp(Ct,s,N); + // cppcheck-suppress uninitvar + (void)wcsncmp(Ct,S,n); + + // no warning is expected for + (void)wcsncmp(Ct,S,N); } void uninivar_strstr(void) diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 544a20c30..ef8ce2615 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -2304,40 +2304,76 @@ void uninivar_strpbrk(void) (void)std::strpbrk(cs,ct); } -void uninivar_strncat(void) +void uninivar_strncat(char *Ct, char *S, size_t N) { char *ct; char *s; size_t n; // cppcheck-suppress uninitvar (void)std::strncat(ct,s,n); + // cppcheck-suppress uninitvar + (void)std::strncat(ct,S,N); + // cppcheck-suppress uninitvar + (void)std::strncat(Ct,s,N); + // cppcheck-suppress uninitvar + (void)std::strncat(Ct,S,n); + + // no warning is expected for + (void)std::strncat(Ct,S,N); } -void uninivar_wcsncat(void) +void uninivar_wcsncat(wchar_t *Ct, wchar_t *S, size_t N) { wchar_t *ct; wchar_t *s; size_t n; // cppcheck-suppress uninitvar (void)std::wcsncat(ct,s,n); + // cppcheck-suppress uninitvar + (void)std::wcsncat(ct,S,N); + // cppcheck-suppress uninitvar + (void)std::wcsncat(Ct,s,N); + // cppcheck-suppress uninitvar + (void)std::wcsncat(Ct,S,n); + + // no warning is expected for + (void)std::wcsncat(Ct,S,N); } -void uninivar_strncmp(void) +void uninivar_strncmp(char *Ct, char *S, size_t N) { char *ct; char *s; size_t n; // cppcheck-suppress uninitvar (void)std::strncmp(ct,s,n); + // cppcheck-suppress uninitvar + (void)std::strncmp(ct,S,N); + // cppcheck-suppress uninitvar + (void)std::strncmp(Ct,s,N); + // cppcheck-suppress uninitvar + (void)std::strncmp(Ct,S,n); + + // no warning is expected for + (void)std::strncmp(Ct,S,N); } -void uninivar_wcsncmp(void) +void uninivar_wcsncmp(wchar_t *Ct, wchar_t *S, size_t N) { wchar_t *ct; wchar_t *s; size_t n; // cppcheck-suppress uninitvar (void)std::wcsncmp(ct,s,n); + // cppcheck-suppress uninitvar + (void)std::wcsncmp(ct,S,N); + // cppcheck-suppress uninitvar + (void)std::wcsncmp(Ct,s,N); + // cppcheck-suppress uninitvar + (void)std::wcsncmp(Ct,S,n); + + // no warning is expected for + (void)std::wcsncmp(Ct,S,N); } void uninivar_strstr(void)