Track curly brace level in extract_c_parameters

https://github.com/david-a-wheeler/flawfinder/issues/25
https://gitlab.com/gitlab-org/gitlab/-/issues/327032
This commit is contained in:
Greg Myers 2021-04-30 13:27:58 -06:00 committed by GitHub
parent 1ff740623b
commit 7defaf1fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -529,6 +529,7 @@ def extract_c_parameters(text, pos=0):
parameters = [""] # Insert 0th entry, so 1st parameter is parameter[1].
currentstart = i
parenlevel = 1
curlylevel = 0
instring = 0 # 1=in double-quote, 2=in single-quote
incomment = 0
while i < len(text):
@ -579,7 +580,11 @@ def extract_c_parameters(text, pos=0):
# print " EXTRACT_C_PARAMETERS: ", text[pos:pos+80]
# print " RESULTS: ", parameters
return parameters
elif c == ';':
elif c == '{':
curlylevel += 1
elif c == '}':
curlylevel -= 1
elif c == ';' and curlylevel < 1:
internal_warn(
"Parsing failed to find end of parameter list; "
"semicolon terminated it in %s" % text[pos:pos + 200])