internal/span: handle invalid column values to avoid crashing

This might not be necessary after we fix handling for line directives,
but it's always better to avoid the panic here.

Updates golang/go#34433

Change-Id: Ica4fb571dff6753fb15bf8d397c55f713284aa27
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196662
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/span/utf16.go b/internal/span/utf16.go
index 55e6924..561b3fa 100644
--- a/internal/span/utf16.go
+++ b/internal/span/utf16.go
@@ -29,6 +29,8 @@
 	if colZero == 0 {
 		// 0-based column 0, so it must be chr 1
 		return 1, nil
+	} else if colZero < 0 {
+		return -1, fmt.Errorf("ToUTF16Column: column is invalid (%v)", colZero)
 	}
 	// work out the offset at the start of the line using the column
 	lineOffset := offset - colZero
@@ -41,6 +43,7 @@
 
 	// Now, truncate down to the supplied column.
 	start = start[:colZero]
+
 	// and count the number of utf16 characters
 	// in theory we could do this by hand more efficiently...
 	return len(utf16.Encode([]rune(string(start)))) + 1, nil