Fix line-number counting in doc.go.
There's an off-by-one when skipping blank lines. The initial logic also has an
off-by-one but since it starts lineNo 0-based and then switches to 1-based, it
cancels out.
The decl error line number also was not of where the decl began.
Change-Id: I58fd157dad3276cb9de52ac48ff8c7c73e40f337
Reviewed-on: https://boringssl-review.googlesource.com/7959
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/util/doc.go b/util/doc.go
index fe5cdc2..50da8d2 100644
--- a/util/doc.go
+++ b/util/doc.go
@@ -274,13 +274,12 @@
return nil, err
}
- lineNo := 0
+ lineNo := 1
found := false
for i, line := range lines {
- lineNo++
if line == cppGuard {
lines = lines[i+1:]
- lineNo++
+ lineNo += i + 1
found = true
break
}
@@ -302,9 +301,9 @@
}
for i, line := range lines {
- lineNo++
if len(line) > 0 {
lines = lines[i:]
+ lineNo += i
break
}
}
@@ -390,6 +389,7 @@
if len(lines) == 0 {
return nil, errors.New("expected decl at EOF")
}
+ declLineNo := lineNo
decl, lines, lineNo, err = extractDecl(lines, lineNo)
if err != nil {
return nil, err
@@ -409,12 +409,12 @@
// detected by starting with “The” or “These”.
if len(comment) > 0 &&
!strings.HasPrefix(comment[0], name) &&
- !strings.HasPrefix(comment[0], "A " + name) &&
- !strings.HasPrefix(comment[0], "An " + name) &&
+ !strings.HasPrefix(comment[0], "A "+name) &&
+ !strings.HasPrefix(comment[0], "An "+name) &&
!strings.HasPrefix(decl, "#define ") &&
!strings.HasPrefix(comment[0], "The ") &&
!strings.HasPrefix(comment[0], "These ") {
- return nil, fmt.Errorf("Comment for %q doesn't seem to match just above %s:%d\n", name, path, lineNo)
+ return nil, fmt.Errorf("Comment for %q doesn't seem to match line %s:%d\n", name, path, declLineNo)
}
anchor := sanitizeAnchor(name)
// TODO(davidben): Enforce uniqueness. This is