Merge pull request #21 from duongdominhchau/master

Fix misrecognized number separator in C++14
This commit is contained in:
David A. Wheeler 2021-01-03 12:58:36 -05:00 committed by GitHub
commit 40b540d6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View File

@ -1461,6 +1461,7 @@ def process_c_file(f, patch_infos):
linenumber = 1
ignoreline = -1
cpplanguage = f.endswith(".cpp") or f.endswith(".cxx") or f.endswith(".cc")
incomment = 0
instring = 0
linebegin = 1
@ -1644,9 +1645,12 @@ def process_c_file(f, patch_infos):
startpos + max_lookahead]
hit.hook(hit)
elif p_digits.match(c):
while i < len(text) and p_digits.match(
text[i]): # Process a number.
i += 1
while i < len(text): # Process a number.
# C does not have digit separator
if p_digits.match(text[i]) or (cpplanguage and text[i] == "'"):
i += 1
else:
break
# else some other character, which we ignore.
# End of loop through text. Wrap up.
if codeinline:

View File

@ -66,11 +66,21 @@ test_008: $(FLAWFINDER) test.c
test-results-008.txt
@diff -u correct-results-008.txt test-results-008.txt
test_009: $(FLAWFINDER) test-cpp-digit-separator.cpp
@echo 'test_009 (C++ digit separator)'
# C++ file should have no problem recognizing ' as digit separator
@$(PYTHON) $(FLAWFINDER) test-cpp-digit-separator.cpp > /dev/null
# C file should fail with unterminated char literal error
@$(PYTHON) $(FLAWFINDER) test-cpp-digit-separator.c 2>&1 \
| grep 'File ended while in string.' \
> /dev/null
# Run all tests on *one* version of Python;
# output shows differences from expected results.
# If everything works as expected, it just prints test numbers.
# Set PYTHON as needed, including to ""
test: test_001 test_002 test_003 test_004 test_005 test_006 test_007 test_008
test: test_001 test_002 test_003 test_004 test_005 test_006 test_007 test_008 \
test_009
@echo 'All tests pass!'
# Usual check routine. Run all tests using *both* python2 and python3.

View File

@ -0,0 +1 @@
int main() { return 0'000; }

View File

@ -0,0 +1 @@
int main() { return 0'000; }