crop limits beyond available lines
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 12 Nov 2022 23:06:49 +0000 (00:06 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 18 Nov 2022 00:25:46 +0000 (01:25 +0100)
Silence warnings about unitialized values.

barcat
t/t1514-limit_beyond_end.in [new symlink]
t/t1514-limit_beyond_end_-L-5.out [new file with mode: 0644]

diff --git a/barcat b/barcat
index b65271e303c9f826470605ecba636708564fb420..35ef3b3d314a7117f02f886aa717076671744868 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -194,7 +194,7 @@ sub color {
 sub show_lines {
 
 state $nr =
-       $opt{hidemin} < 0 ? @lines + $opt{hidemin} + 1 :
+       $opt{hidemin} < 0 ? max(0, @lines + $opt{hidemin} + 1) :
        $opt{hidemin};
 @lines > $nr or return;
 
@@ -203,7 +203,7 @@ if (defined $opt{hidemax}) {
        if ($opt{hidemin} and $opt{hidemin} < 0) {
                $limit -= $opt{hidemax} - 1;
        }
-       else {
+       elsif ($opt{hidemax} <= $limit) {
                $limit = $opt{hidemax} - 1;
        }
 }
diff --git a/t/t1514-limit_beyond_end.in b/t/t1514-limit_beyond_end.in
new file mode 120000 (symlink)
index 0000000..02f1de9
--- /dev/null
@@ -0,0 +1 @@
+t1700-empty_input.in
\ No newline at end of file
diff --git a/t/t1514-limit_beyond_end_-L-5.out b/t/t1514-limit_beyond_end_-L-5.out
new file mode 100644 (file)
index 0000000..e69de29