From 19591298f1a8a189f403fe6a94b7779c2d8df13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 16 Apr 2018 10:53:29 +0200 Subject: [PATCH] misc.py: Fixed FP for string concatenation --- addons/misc.py | 6 ++++++ addons/test/misc-test.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/misc.py b/addons/misc.py index 8e2f405b0..521cf22e6 100644 --- a/addons/misc.py +++ b/addons/misc.py @@ -42,6 +42,12 @@ def check(data): elif tok1 == ']' and tok2 == '=' and tok3 == '{': arrayInit = True elif arrayInit and (tok1 in [',', '{']) and tok2.startswith('"') and tok3.startswith('"'): + if tok1 == '{': + i2 = i + 1 + while i2 < len(data.rawTokens) and data.rawTokens[i2].str not in [',', '}']: + i2 = i2 + 1 + if i2 >= len(data.rawTokens) or data.rawTokens[i2].str != ',': + continue reportError(data.rawTokens[i], 'style', 'string concatenation', 'stringConcatInArrayInit') for arg in sys.argv[1:]: diff --git a/addons/test/misc-test.c b/addons/test/misc-test.c index 7739277f3..1eff04abe 100644 --- a/addons/test/misc-test.c +++ b/addons/test/misc-test.c @@ -1,4 +1,5 @@ // To test: -// ~/cppcheck/cppcheck --dump cert-test.c && python ../cert.py -verify cert-test.c.dump +// ~/cppcheck/cppcheck --dump misc-test.c && python ../misc.py -verify misc-test.c.dump -const char *a[] = {"a" "b"}; // stringConcatInArrayInit +const char *a[] = {"a" "b"}; +const char *b[] = {"a","b" "c"}; // stringConcatInArrayInit