Visitar URL original
Fix hexadecimal float parsing when dot is followed by letter (#182) · versat/simplecpp@71adfce · GitHub
Skip to content

Commit 71adfce

Browse files
rikardfalkeborndanmar
authored andcommitted
Fix hexadecimal float parsing when dot is followed by letter (cppcheck-opensource#182)
1 parent 8e260b2 commit 71adfce

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎simplecpp.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ void simplecpp::TokenList::combineOperators()
768768
if (tok->previous && tok->previous->number) {
769769
tok->setstr(tok->previous->str() + '.');
770770
deleteToken(tok->previous);
771-
if (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("Ee"))) {
771+
if (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp"))) {
772772
tok->setstr(tok->str() + tok->next->str());
773773
deleteToken(tok->next);
774774
}

‎test.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,15 @@ static void combineOperators_floatliteral()
153153
ASSERT_EQUALS("1E7", preprocess("1E7"));
154154
ASSERT_EQUALS("1E-7", preprocess("1E-7"));
155155
ASSERT_EQUALS("1E+7", preprocess("1E+7"));
156+
ASSERT_EQUALS("1.e+7", preprocess("1.e+7"));
156157
ASSERT_EQUALS("0x1E + 7", preprocess("0x1E+7"));
158+
ASSERT_EQUALS("0x1ffp10", preprocess("0x1ffp10"));
159+
ASSERT_EQUALS("0x0p-1", preprocess("0x0p-1"));
160+
ASSERT_EQUALS("0x1.p0", preprocess("0x1.p0"));
161+
ASSERT_EQUALS("0xf.p-1", preprocess("0xf.p-1"));
157162
ASSERT_EQUALS("0x1.2p3", preprocess("0x1.2p3"));
163+
ASSERT_EQUALS("0x1.ap3", preprocess("0x1.ap3"));
164+
ASSERT_EQUALS("0x1.2ap3", preprocess("0x1.2ap3"));
158165
ASSERT_EQUALS("0x1p+3", preprocess("0x1p+3"));
159166
ASSERT_EQUALS("0x1p+3f", preprocess("0x1p+3f"));
160167
ASSERT_EQUALS("0x1p+3L", preprocess("0x1p+3L"));

0 commit comments

Comments
 (0)