groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 10/27: [refer]: Fix Savannah #62391.


From: G. Branden Robinson
Subject: [groff] 10/27: [refer]: Fix Savannah #62391.
Date: Tue, 3 May 2022 14:27:16 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 5383f0ff88aa6622c65837e15b6794120275b77e
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun May 1 23:24:07 2022 -0500

    [refer]: Fix Savannah #62391.
    
    [refer]: Fix off-by-one error in line number for some diagnostics.
    
    * src/preproc/refer/command.cpp (input_item::get_location): Decrement
      reported line number by one after looping over input so that we report
      the line number as it was before the last newline character seen.
      This off-by-one error was partially masked by...
    
    * src/preproc/refer/refer.cpp (do_file): ...initialzation of
      `current_lineno` to zero.  However, for syntax problems (as opposed to
      the semantic problems of refer(1) command processing), this could
      result in complaints about the line number before they occurred,
      even on "line zero".  Initialize the variable to 1.
    
    Fixes <https://savannah.gnu.org/bugs/?62391>.
---
 ChangeLog                     | 19 +++++++++++++++++++
 src/preproc/refer/command.cpp |  1 +
 src/preproc/refer/refer.cpp   |  2 +-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 060f2db5..f381868e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2022-05-02  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [refer]: Fix off-by-one error in line number for some
+       diagnostics.
+
+       * src/preproc/refer/command.cpp (input_item::get_location):
+       Decrement reported line number by one after looping over input
+       so that we report the line number as it was before the last
+       newline character seen.  This off-by-one error was partially
+       masked by...
+       * src/preproc/refer/refer.cpp (do_file): ...initialzation of
+       `current_lineno` to zero.  However, for syntax problems (as
+       opposed to the semantic problems of refer(1) command
+       processing), this could result in complaints about the line
+       number before they occurred, even on "line zero".  Initialize
+       the variable to 1.
+
+       Fixes <https://savannah.gnu.org/bugs/?62391>.
+
 2022-05-02  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/preproc/refer/tests/report-correct-line-numbers.sh: Add
diff --git a/src/preproc/refer/command.cpp b/src/preproc/refer/command.cpp
index 7860e3d8..d7832e8a 100644
--- a/src/preproc/refer/command.cpp
+++ b/src/preproc/refer/command.cpp
@@ -87,6 +87,7 @@ int input_item::get_location(const char **filenamep, int 
*linenop)
     for (const char *p = buffer.contents(); p < e; p++)
       if (*p == '\n')
        ln++;
+    ln--; // Back up to identify line number _before_ last seen newline.
     *linenop = ln;
   }
   return 1;
diff --git a/src/preproc/refer/refer.cpp b/src/preproc/refer/refer.cpp
index 0fd79f69..90f8f0ff 100644
--- a/src/preproc/refer/refer.cpp
+++ b/src/preproc/refer/refer.cpp
@@ -440,8 +440,8 @@ static void do_file(const char *filename)
   normalize_for_lf(fn);
   current_filename = fn.contents();
   fprintf(outfp, ".lf 1 %s\n", current_filename);
+  current_lineno = 1;
   string line;
-  current_lineno = 0;
   for (;;) {
     line.clear();
     for (;;) {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]