diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-04-14 16:07:15 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-04-15 11:46:04 +0000 |
| commit | b7285264646c21702afa7317ed90a0d6c06814f8 (patch) | |
| tree | 341fb1bea72994fb800a62b79755dc89eaf078ff /pkg/ast | |
| parent | 9b260b0e8a71a22a5fee1bfe673ecc134f6fc4df (diff) | |
tools/syz-declextract: ignore files with non US-ASCII chars
Diffstat (limited to 'pkg/ast')
| -rw-r--r-- | pkg/ast/scanner.go | 22 | ||||
| -rw-r--r-- | pkg/ast/testdata/errors.txt | 2 |
2 files changed, 15 insertions, 9 deletions
diff --git a/pkg/ast/scanner.go b/pkg/ast/scanner.go index 9a5becf1c..67dd80e52 100644 --- a/pkg/ast/scanner.go +++ b/pkg/ast/scanner.go @@ -221,14 +221,11 @@ func (s *scanner) scanStr(pos Pos) string { } } lit := string(s.data[pos.Off+1 : s.off]) - for i := 0; i < len(lit); i++ { - if lit[i] < 0x20 || lit[i] >= 0x80 { - pos1 := pos - pos1.Col += i + 1 - pos1.Off += i + 1 - s.Errorf(pos1, "illegal character %#U in string literal", lit[i]) - break - } + if i := IsValidStringLit(lit); i >= 0 { + pos1 := pos + pos1.Col += i + 1 + pos1.Off += i + 1 + s.Errorf(pos1, "illegal character %#U in string literal %q", lit[i], lit) } s.next() if closing != '`' { @@ -352,3 +349,12 @@ func (s *scanner) pos() Pos { Col: s.col, } } + +func IsValidStringLit(lit string) int { + for i := 0; i < len(lit); i++ { + if lit[i] < 0x20 || lit[i] >= 0x80 { + return i + } + } + return -1 +} diff --git a/pkg/ast/testdata/errors.txt b/pkg/ast/testdata/errors.txt index a8a4aa197..0d8488134 100644 --- a/pkg/ast/testdata/errors.txt +++ b/pkg/ast/testdata/errors.txt @@ -20,7 +20,7 @@ int_flags4 = 1, -2- ### bad integer "-2-" str_flags0 = "foo", "bar" str_flags1 = "non terminated ### string literal is not terminated -str_flags2 = "bad chars здесь" ### illegal character U+00D0 'Ð' in string literal +str_flags2 = "bad chars здесь" ### illegal character U+00D0 'Ð' in string literal "bad chars здесь" str_flags3 = "string", not a string ### unexpected identifier, expecting '\n' str_flags4 = "string", 42 ### unexpected int, expecting string, hex string, identifier str_flags5 = `x` ### bad hex string literal: encoding/hex: invalid byte: U+0078 'x' |
