NetBSD Problem Report #55728

From rhialto@falu.nl  Wed Oct 14 19:03:47 2020
Return-Path: <rhialto@falu.nl>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 53E0A1A921F
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 14 Oct 2020 19:03:47 +0000 (UTC)
Message-Id: <202010141903.09EJ3ap6028970@murthe.falu.nl>
Date: Wed, 14 Oct 2020 21:03:36 +0200 (CEST)
From: rhialto@NetBSD.org
Reply-To: rhialto@falu.nl
To: gnats-bugs@NetBSD.org
Subject: bug in curses_pad: shows incorrect part of the pad
X-Send-Pr-Version: 3.95

>Number:         55728
>Category:       lib
>Synopsis:       bug in curses_pad: shows incorrect part of the pad
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 14 19:05:00 +0000 2020
>Last-Modified:  Fri Oct 16 23:35:01 +0000 2020
>Originator:     Rhialto
>Release:        NetBSD 9.0
>Organization:
>Environment:
System: NetBSD murthe.falu.nl 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
	The curses_pad(3) manual page describes a "pad", which is some
	text area larger than your window. A rectangular fragment from the pad
	may be copied to the screen:

     int
     prefresh(WINDOW *pad, int pbeg_y, int pbeg_x, int sbeg_y, int sbeg_x,
         int smax_y, int smax_x);

     The prefresh() function causes curses to propagate changes made to the
     pad specified by pad to the terminal display.  A rectangular area of the
     pad starting at column and row pbeg_y, pbeg_x is copied to the
     corresponding rectangular area of the terminal starting at column and row
     sbeg_y, sbeg_x and extending to smax_y, smax_x.

	The program below creates such a pad, 1000 lines long, and attempts
	to show line 100ff on the screen.

	What happens in reality is that line 100ff are briefly displayed
	(if you can see it that quickly) but are immediately overwritten
	with line 0ff.

	Each time the enter key is pressed, it tries to go ahead 10 lines.
	The flashing is sometimes visible.

	Expected behaviour: the program shows Line 100 and further.

>How-To-Repeat:
	Using this program (curs.c) which you can run as a shell script
	to compile it.
# /*
cc curs.c -lcurses -o curs
exit $?
*/

#include <curses.h>

int main(int argc, char **argv)
{
    initscr();
    keypad(stdscr, TRUE);
    clearok(stdscr, TRUE);
    noecho();

    int maxx = getmaxx(stdscr);
    int maxy = getmaxy(stdscr);

    mvwaddstr(stdscr, maxy-1, 0, "Loading...");
    wrefresh(stdscr);

    int rows = 1000;
    int width = maxx - 4;

    WINDOW *pad = newpad(rows, width + 2);
    int i;
    for (i = 0; i < rows; i++) {
	char tmp[80];
	sprintf(tmp, "Line %d", i);
	mvwaddstr(pad, i, 0, tmp);
    }

    int y = 100;
    int x = (maxx - width) / 2;

    while (y < rows) {
	/*
	 * According to curses_pad(3), this should show  Line 100, Line 101,
	 * etc.  It does even print that, briefly (if you can see it), but it
	 * is overwritten immediately with Line 0, Line 1, Line 2, etc.
	 */
	prefresh(pad, y,0,  0,x,  maxy-1,x+width);

	int k = wgetch(pad);

	y += 10;
    }

    endwin();
}
>Fix:
	None known.

-Olaf.
-- 
Olaf 'Rhialto' Seibert -- rhialto at falu dot nl
___  Anyone who is capable of getting themselves made President should on
\X/  no account be allowed to do the job.       --Douglas Adams, "THGTTG"

>Audit-Trail:
From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/55728: bug in curses_pad: shows incorrect part of the pad
Date: Thu, 15 Oct 2020 16:07:07 +0300

 Just a quick remark that it seems to be a bit better on current (there
 is no Line 0... splattered over the screen), but still wrong.  I get
 this after the second refresh:

   Line 111
   Line 112
   Line 113
   Line 114
   Line 115
   Line 116
   Line 117
   Line 118
   Line 119
   Line 120
   Line 121
   Line 122
 LoLine 123

   Line 124
   Line 125
   Line 126
   Line 127
   Line 128
   Line 129
   Line 130
   Line 131
   Line 132
 LoLine 133


 -uwe

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/55728: bug in curses_pad: shows incorrect part of the pad
Date: Thu, 15 Oct 2020 17:12:14 +0300

 Actually, shouldn't that program also do cbreak()?  With cbreak it
 seems to work fine on current except for the cursor positioning issue:
 scrolling optimization moves the cursor up 10 lines then 10 more, that
 it stays in the 4th line.

 -uwe

From: Rhialto <rhialto@falu.nl>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org, rhialto@falu.nl
Subject: Re: lib/55728: bug in curses_pad: shows incorrect part of the pad
Date: Fri, 16 Oct 2020 20:29:27 +0200

 Yes I think you're right. The original case I derived this from
 (a terminal epub reader in python: https://github.com/wustho/epr) did
 that.
 With some cheating I put a -current libcurses in my 9.0 system and that
 made things much better.

 I'm not so bothered by where the cursor ends up; I don't know how well
 this is specified anyway. "epr" seems to hide the cursor anyway.

 If you want to keep the PR open for the cursor position, let's do that,
 otherwise it can be closed.

 -Olaf

From: Brett Lymn <blymn@internode.on.net>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,
        rhialto@falu.nl
Subject: Re: lib/55728: bug in curses_pad: shows incorrect part of the pad
Date: Sat, 17 Oct 2020 07:42:27 +1030

 On Fri, Oct 16, 2020 at 06:30:02PM +0000, Rhialto wrote:
 >  
 >  I'm not so bothered by where the cursor ends up; I don't know how well
 >  this is specified anyway. "epr" seems to hide the cursor anyway.
 >  

 I am.  It indicates that the position is not being tracked properly and
 could cause issues if soemthing assumed the position of the cursor had
 not changed.

 -- 
 Brett Lymn
 --
 Sent from my NetBSD device.

 "We are were wolves",
 "You mean werewolves?",
 "No we were wolves, now we are something else entirely",
 "Oh"

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.