]> Cypherpunks repositories - gostls13.git/commitdiff
go/scanner: align line and column limit with the compiler's limit
authorDamien Neil <dneil@google.com>
Wed, 5 Apr 2023 16:28:00 +0000 (09:28 -0700)
committerDamien Neil <dneil@google.com>
Thu, 6 Apr 2023 19:14:11 +0000 (19:14 +0000)
The compiler disallows line and column numbers > (1<<30)
(cmd/compiler/internal/syntax.PosMax).

Set the go/scanner limit to the same rather than off by one.

For #59180

Change-Id: Ibf9e0e6826d6f6230b0d492543b7e906298a0524
Reviewed-on: https://go-review.googlesource.com/c/go/+/482595
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Damien Neil <dneil@google.com>

src/cmd/compile/internal/syntax/pos.go
src/go/scanner/scanner.go

index b5e53d268bd247d51190cb07d46a4f4220dab685..dd25d4f249dee6b7b0ed8b9dc937a6e4724b00f8 100644 (file)
@@ -8,6 +8,8 @@ import "fmt"
 
 // PosMax is the largest line or column value that can be represented without loss.
 // Incoming values (arguments) larger than PosMax will be set to PosMax.
+//
+// Keep this consistent with maxLineCol in go/scanner.
 const PosMax = 1 << 30
 
 // A Pos represents an absolute (line, col) source position
index 0cd9f5901d0bbae277e44ab79a8975ec86c62418..75f835d3105d67848fc20d40ea7d626721bd4abd 100644 (file)
@@ -255,7 +255,8 @@ func (s *Scanner) updateLineInfo(next, offs int, text []byte) {
 
        // Put a cap on the maximum size of line and column numbers.
        // 30 bits allows for some additional space before wrapping an int32.
-       const maxLineCol = 1<<30 - 1
+       // Keep this consistent with cmd/compile/internal/syntax.PosMax.
+       const maxLineCol = 1 << 30
        var line, col int
        i2, n2, ok2 := trailingDigits(text[:i-1])
        if ok2 {