diff options
author | Balajiganapathi S <balajiganapathi.s@gmail.com> | 2017-10-25 16:12:07 +0800 |
---|---|---|
committer | Christian Parpart <christian@ethereum.org> | 2018-08-08 18:05:51 +0800 |
commit | 09a36cba0223c16248335703412cee019c7aa59f (patch) | |
tree | ae444498ba2265538c54d4af63742b8bec32da43 /libsolidity/parsing | |
parent | 0000bfc604b985c47ab153f4172596b860c7cce8 (diff) | |
download | dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.tar dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.tar.gz dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.tar.bz2 dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.tar.lz dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.tar.xz dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.tar.zst dexon-solidity-09a36cba0223c16248335703412cee019c7aa59f.zip |
Add stricter hex underscore rules
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r-- | libsolidity/parsing/Scanner.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp index 65189b19..c223779e 100644 --- a/libsolidity/parsing/Scanner.cpp +++ b/libsolidity/parsing/Scanner.cpp @@ -726,21 +726,26 @@ Token::Value Scanner::scanHexString() void Scanner::scanDecimalDigits() { - if (!isDecimalDigit(m_char)) // avoid underscore at beginning - return; - while (isDecimalDigit(m_char) || m_char == '_') + // Parse for regex [:digit:]+(_[:digit:]+)* + + do { + if (!isDecimalDigit(m_char)) + return; + while (isDecimalDigit(m_char)) + addLiteralCharAndAdvance(); + if (m_char == '_') { advance(); - if (!isDecimalDigit(m_char)) // avoid trailing underscore + if (!isDecimalDigit(m_char)) // Trailing underscore. Rollback and allow next step to flag it as illegal { rollback(1); - break; + return; } } - addLiteralCharAndAdvance(); } + while (isDecimalDigit(m_char)); } Token::Value Scanner::scanNumber(char _charSeen) @@ -768,19 +773,17 @@ Token::Value Scanner::scanNumber(char _charSeen) addLiteralCharAndAdvance(); if (!isHexDigit(m_char)) return Token::Illegal; // we must have at least one hex digit after 'x'/'X' - while (isHexDigit(m_char) || m_char == '_') // same logic as scanDecimalDigits + char last = m_char; + while (isHexDigit(m_char) || m_char == '_') // Unlike decimal digits, we keep the underscores for later validation { - if (m_char == '_') - { - advance(); - if (!isHexDigit(m_char)) // avoid trailing underscore - { - rollback(1); - break; - } - } + if (m_char == '_' && last == '_') + return Token::Illegal; // Double underscore + + last = m_char; addLiteralCharAndAdvance(); } + if (last == '_') + return Token::Illegal; // Trailing underscore } else if (isDecimalDigit(m_char)) // We do not allow octal numbers |