misc.py: Fixed FP for string concatenation

This commit is contained in:
Daniel Marjamäki 2018-04-16 10:53:29 +02:00
parent a8cd2ac0ea
commit 19591298f1
2 changed files with 9 additions and 2 deletions

View File

@ -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:]:

View File

@ -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