diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs index 58370a6548..301d21b957 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs @@ -162,6 +162,10 @@ namespace ICSharpCode.NRefactory.Parser.CSharp while (IsHex((char)ReaderPeek())) { sb.Append(Char.ToUpper((char)ReaderRead(), CultureInfo.InvariantCulture)); } + if (sb.Length == 0) { + sb.Append('0'); // dummy value to prevent exception + errors.Error(y, x, "Invalid hexadecimal integer literal"); + } ishex = true; prefix = "0x"; peek = (char)ReaderPeek(); diff --git a/src/Libraries/NRefactory/Test/Lexer/CSharp/NumberLexerTest.cs b/src/Libraries/NRefactory/Test/Lexer/CSharp/NumberLexerTest.cs index a670ae22cc..c2b92a6ebb 100644 --- a/src/Libraries/NRefactory/Test/Lexer/CSharp/NumberLexerTest.cs +++ b/src/Libraries/NRefactory/Test/Lexer/CSharp/NumberLexerTest.cs @@ -70,6 +70,16 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp CheckToken("0xAB1f", 0xAB1f); } + [Test] + public void InvalidHexadecimalInteger() + { + // don't check result, just make sure there is no exception + GenerateLexer(new StringReader("0x2GF")).NextToken(); + GenerateLexer(new StringReader("0xG2F")).NextToken(); + // SD2-457 + GenerateLexer(new StringReader("0x")).NextToken(); + } + [Test] public void TestLongHexadecimalInteger() {