From b424056721de48b883ba8172e989386c5d471abc Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 30 Dec 2019 21:52:36 +0100 Subject: [PATCH] cgo: fix a bug in number tokenization --- cgo/const.go | 4 +++- cgo/const_test.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cgo/const.go b/cgo/const.go index f69bbb81..c2451bc0 100644 --- a/cgo/const.go +++ b/cgo/const.go @@ -140,8 +140,10 @@ func (t *tokenizer) Next() { if c == '.' { hasDot = true } - if (c >= '0' && c <= '9') || c == '.' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') { + if c >= '0' && c <= '9' || c == '.' || c == '_' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' { tokenLen = i + 1 + } else { + break } } t.value = t.buf[:tokenLen] diff --git a/cgo/const_test.go b/cgo/const_test.go index eaac3047..cfba4507 100644 --- a/cgo/const_test.go +++ b/cgo/const_test.go @@ -30,6 +30,7 @@ func TestParseConst(t *testing.T) { {`'a'`, `'a'`}, {`0b10`, `0b10`}, {`0x1234_5678`, `0x1234_5678`}, + {`5 5`, `error: 1:3: unexpected token INT`}, // test for a bugfix } { fset := token.NewFileSet() startPos := fset.AddFile("", -1, 1000).Pos(0)