Skip to content

Commit

Permalink
Fix bug with --no-number-headers when header is not at start of file.
Browse files Browse the repository at this point in the history
Calculation in vlinenum was assuming header starts at position 0.
Related to #566.
  • Loading branch information
gwsw committed Sep 3, 2024
1 parent 6cd6b11 commit 47a7b8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@

* Fix bug when using +:n +:p +:x or +:d on the command line (github #552).

* Fix bug with --no-number-headers when header is not at start of file
(github #566).

======================================================================

Major changes between "less" versions 661 and 664
Expand Down
12 changes: 10 additions & 2 deletions linenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extern int sigs;
extern int sc_height;
extern int header_lines;
extern int nonum_headers;
extern POSITION header_start_pos;

/*
* Initialize the line number structures.
Expand Down Expand Up @@ -511,7 +512,14 @@ public void scan_eof(void)
*/
public LINENUM vlinenum(LINENUM linenum)
{
if (nonum_headers)
linenum = (linenum < header_lines) ? 0 : linenum - header_lines;
if (nonum_headers && header_lines > 0)
{
LINENUM header_start_line = find_linenum(header_start_pos);
if (header_start_line != 0)
{
LINENUM header_end_line = header_start_line + header_lines; /* first line after header */
linenum = (linenum < header_end_line) ? 0 : linenum - header_end_line + 1;
}
}
return linenum;
}
4 changes: 3 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,9 @@ v663 8/16/24 Fix ^X bug when output is not a tty.
v664 Fix Windows compile error.
v659.1 Add --no-paste; add --no-edit-warn; add TAB for -- command;
add LESSANSIOSCALLOW and LESSANSIOSCCCHARS; fix bug searching
near invalid UTF-8 sequence; add LESS_SHELL_LINES.
near invalid UTF-8 sequence; add LESS_SHELL_LINES; fix bug
with --no-number-headers.
*/

char version[] = "659.1x";

0 comments on commit 47a7b8e

Please sign in to comment.