misc.py: fixed FP

This commit is contained in:
Daniel Marjamäki 2018-04-16 12:55:27 +02:00
parent 2a657cfd08
commit 9579b12be9
2 changed files with 27 additions and 8 deletions

View File

@ -28,27 +28,33 @@ def simpleMatch(token, pattern):
token = token.next token = token.next
return True return True
def isStringLiteral(tokenString):
return tokenString.startswith('"')
# check data # check data
def check(data): def check(data):
arrayInit = False arrayInit = False
for i in range(len(data.rawTokens)): rawTokens = data.rawTokens
for i in range(len(rawTokens)):
if i < 2: if i < 2:
continue continue
tok1 = data.rawTokens[i-2].str tok1 = rawTokens[i-2].str
tok2 = data.rawTokens[i-1].str tok2 = rawTokens[i-1].str
tok3 = data.rawTokens[i-0].str tok3 = rawTokens[i-0].str
if tok3 == '}': if tok3 == '}':
arrayInit = False arrayInit = False
elif tok1 == ']' and tok2 == '=' and tok3 == '{': elif tok1 == ']' and tok2 == '=' and tok3 == '{':
arrayInit = True arrayInit = True
elif arrayInit and (tok1 in [',', '{']) and tok2.startswith('"') and tok3.startswith('"'): elif arrayInit and (tok1 in [',', '{']) and isStringLiteral(tok2) and isStringLiteral(tok3):
if tok1 == '{': if tok1 == '{':
i2 = i + 1 i2 = i + 1
while i2 < len(data.rawTokens) and data.rawTokens[i2].str not in [',', '}']: while i2 < len(rawTokens) and rawTokens[i2].str not in [',', '}']:
i2 = i2 + 1 i2 = i2 + 1
if i2 >= len(data.rawTokens) or data.rawTokens[i2].str != ',': if i2 >= len(rawTokens) or rawTokens[i2].str != ',':
continue continue
reportError(data.rawTokens[i], 'style', 'string concatenation', 'stringConcatInArrayInit') if i + 2 < len(rawTokens) and isStringLiteral(rawTokens[i+1].str) and isStringLiteral(rawTokens[i+2].str):
continue
reportError(rawTokens[i], 'style', 'string concatenation', 'stringConcatInArrayInit')
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg == '-verify': if arg == '-verify':

View File

@ -3,3 +3,16 @@
const char *a[] = {"a" "b"}; const char *a[] = {"a" "b"};
const char *b[] = {"a","b" "c"}; // stringConcatInArrayInit const char *b[] = {"a","b" "c"}; // stringConcatInArrayInit
const char *c[] = {
"a\n"
"a\n"
"a\n"
"a\n"
"a\n"
,
"b\n"
"b\n"
"b\n"
"b\n"
"b\n"
};