From 836e0f611e69f12657ca7b4ff1d5747865308e2d Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Mon, 30 Apr 2018 19:40:03 -0400 Subject: [PATCH] cmd/goyacc: fix an off-by-one error in lineno tracking Previously, goyacc's line number tracking would run off by one whenever a multiline comment was used inside of an action, like so: expr: TOKEN { /* Hello. */ } This is because the character after the multi-line comment close marker (i.e., the character immediately after `*/`) was blindly printed out instead of properly accounted for. A newline character after a multi-line comment would fail to increment lineno, for example, and any error messages generated after that point would refer to the wrong line. Similarly, a variable reference after a multi-line comment, like $$.val = &someStruct{Value: /* oops */$1} would copy the $ literally into the resulting Go code. (This was not a problem in practice because multi-line comments are typically followed by whitespace.) Adjust the control flow so the character after the multi-line comment close marker character gets run through the relevant switch statement and accounted for. Change-Id: I276b6ffdb7626101f76811b7ee4804bacc6ef740 Reviewed-on: https://go-review.googlesource.com/110495 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- cmd/goyacc/yacc.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/goyacc/yacc.go b/cmd/goyacc/yacc.go index 062bc47e26..d831f67395 100644 --- a/cmd/goyacc/yacc.go +++ b/cmd/goyacc/yacc.go @@ -1412,8 +1412,7 @@ loop: if nnc == '/' { fcode.WriteRune('*') fcode.WriteRune('/') - c = getrune(finput) - break swt + continue loop } ungetrune(finput, nnc) }