Skip Menu |

This queue is for tickets about the Curses-UI-Grid CPAN distribution.

Report information
The Basics
Id: 132696
Status: new
Priority: 0/
Queue: Curses-UI-Grid

People
Owner: Nobody in particular
Requestors: Matthew.Buchanan [...] Mercy.Net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Off-by-one errors in grid-demo.pl and Grid.pm
Date: Sun, 24 May 2020 22:48:01 +0000
To: "bug-Curses-UI-Grid [...] rt.cpan.org" <bug-Curses-UI-Grid [...] rt.cpan.org>
From: "Buchanan, Matt" <Matthew.Buchanan [...] Mercy.Net>
Hello, There are multiple, related off-by-one errors in grid-demo.pl and Grid.pm. Correcting the errors in grid-demo.pl exposes the error in Grid.pm. (1) grid-demo.pl's Browser demo does not display the last element of @data. The patch below updates -onnextpage, -onprevpage, and fill_data() to resolve this problem. (2) After making these corrections to grid-demo.pl, under certain conditions the program will abort with this message: Can't call method "event_onfocus" without a package or object reference at Curses-UI-Grid-0.15/examples/../lib/Curses/UI/Grid.pm line 1310. The abort occurs when (scalar @data) % $grid->page_size == 1, so to reproduce it one can change the Browser demo grid's height from 20 to 10 (for a page size of 8) or run the program on a 24-row terminal (actual grid height will be 18, for a page size of 16). With 49 elements in @data, the last page will display one row of data. To trigger the abort, use KEY_DOWN to move from the next-to-last page to the last page. The problem appears to be that Grid::get_last_row() stops searching one row too early. The patch below resolves the problem. These errors occur on multiple Perl versions and operating systems: Curses-UI-Grid-0.15 Perl 5.24.4 on OpenBSD 6.4 Perl 5.30.2 on AIX 7.2.3.3 Thanks for your attention. M. B. Buchanan Mercy Technology Services diff -ur grid-demo.pl.orig grid-demo.pl --- grid-demo.pl.orig 2008-05-05 01:18:34.000000000 -0500 +++ grid-demo.pl 2020-05-24 15:02:14.000000000 -0500 @@ -211,7 +211,7 @@ my $row=$grid->get_foused_row; my $offset=$pgsize*$grid->page($pg+1); - if($offset < $#data) { + if($offset <= $#data) { fill_data($offset,$pgsize,\@data,$grid ); } else { $grid->page($pg);return 0; } my $last_row=$grid->get_foused_row; @@ -224,7 +224,7 @@ my ($pgsize,$pg)=($grid->page_size,$grid->page); return 0 unless $pg; my $offset=$pgsize*$grid->page($pg-1); - if($offset < $#data) { + if($offset <= $#data) { fill_data($offset,$pgsize,\@data,$grid ); } else { $grid->page($pg);return 0;} return $grid; @@ -344,11 +344,11 @@ my $data=shift; my $grid=shift; - for my $i (0 .. $limit) { + for my $i (0 .. $limit-1) { my $row=$grid->get_row( $grid->{_rows}[$i+1] ); next unless ref($row); - if($#{$data} <= $offset+$i) { + if($#{$data} < $offset+$i) { $row->hide; $row->{-focusable}=0; next; diff -ur Grid.pm.orig Grid.pm --- Grid.pm.orig 2008-06-09 07:56:01.000000000 -0500 +++ Grid.pm 2020-05-24 14:59:40.000000000 -0500 @@ -1355,7 +1355,7 @@ sub get_last_row { my $this = shift; my $rows = $this->_rows; - for (my $i = $#{$rows}; $i > 1; $i--) { + for (my $i = $#{$rows}; $i > 0; $i--) { my $row = $this->get_row($rows->[$i]); return $row if ($row->focusable && ! $this->hidden); } This electronic mail and any attached documents are intended solely for the named addressee(s) and contain confidential information. If you are not an addressee, or responsible for delivering this email to an addressee, you have received this email in error and are notified that reading, copying, or disclosing this email is prohibited. If you received this email in error, immediately reply to the sender and delete the message completely from your computer system.

Message body is not shown because sender requested not to inline it.