NetBSD Problem Report #55457

From www@netbsd.org  Sun Jul  5 05:36:07 2020
Return-Path: <www@netbsd.org>
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 6A0F21A9217
	for <gnats-bugs@gnats.NetBSD.org>; Sun,  5 Jul 2020 05:36:07 +0000 (UTC)
Message-Id: <20200705053606.5A6661A9218@mollari.NetBSD.org>
Date: Sun,  5 Jul 2020 05:36:06 +0000 (UTC)
From: mforney@mforney.org
Reply-To: mforney@mforney.org
To: gnats-bugs@NetBSD.org
Subject: libcurses: when passed a pad, wget_wch/wgetch calls wrefresh on the pad
X-Send-Pr-Version: www-1.0

>Number:         55457
>Category:       lib
>Synopsis:       libcurses: when passed a pad, wget_wch/wgetch calls wrefresh on the pad
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 05 05:40:00 +0000 2020
>Closed-Date:    Wed Aug 02 15:43:04 +0000 2023
>Last-Modified:  Wed Aug 02 15:43:04 +0000 2023
>Originator:     Michael Forney
>Release:        libcurses trunk as of 2020-07-04
>Organization:
>Environment:
>Description:
When you create a pad with newpad(), then when you read a character
with wget_wch() or wgetch(), it incorrectly calls wrefresh() on the
pad.  This causes a region of the screen (starting at 0, 0) to be
replaced with the contents of the pad.

According to X/Open Curses issue 7, this refresh operation should not
occur when the window is a pad:

> If the current or specified window is not a pad, and it has been moved
> or modified since the last refresh operation, then it will be refreshed
> before another character is read.

>How-To-Repeat:
Here is an example program that illustrates the problem.  It should
write any input to the pad on the second line.  The problem is that
the input also overwrites the first line in addition to displaying on
the second line.

#include <curses.h>
int
main(void)
{
	WINDOW *pad;
	int c;

	initscr();
	cbreak();
	noecho();

	addstr("abcdefghijklmnopqrstuvwxyz0123456789");
	refresh();

	pad = newpad(1, COLS);
	for (;;) {
		c = wgetch(pad);
		waddch(pad, c);
		prefresh(pad, 0, 0, 1, 0, 1, COLS);
	}
	endwin();
}

>Fix:
Adding a check to see if the window is a pad before calling wrefresh
solves the issue:

diff --git a/lib/libcurses/get_wch.c b/lib/libcurses/get_wch.c
index 40a7169..1641c72 100644
--- a/lib/libcurses/get_wch.c
+++ b/lib/libcurses/get_wch.c
@@ -494,7 +494,7 @@ wget_wch(WINDOW *win, wint_t *ch)
 	    && __echoit)
 		return ERR;

-	if (is_wintouched(win))
+	if (!(win->flags & __ISPAD) && is_wintouched(win))
 		wrefresh(win);
 #ifdef DEBUG
 	__CTRACE(__CTRACE_INPUT, "wget_wch: __echoit = %d, "
diff --git a/lib/libcurses/getch.c b/lib/libcurses/getch.c
index c96965f..b8a8e8a 100644
--- a/lib/libcurses/getch.c
+++ b/lib/libcurses/getch.c
@@ -809,11 +809,11 @@ wgetch(WINDOW *win)
 	    && __echoit)
 		return ERR;

-	if (is_wintouched(win))
-		wrefresh(win);
-	else {
-		if ((_cursesi_screen->curscr->cury != (win->begy + win->cury))
-		    || (_cursesi_screen->curscr->curx != (win->begx + win->curx))) {
+	if (!(win->flags & __ISPAD)) {
+		if (is_wintouched(win))
+			wrefresh(win);
+		else if ((_cursesi_screen->curscr->cury != (win->begy + win->cury))
+		         || (_cursesi_screen->curscr->curx != (win->begx + win->curx))) {
 #ifdef DEBUG
 			__CTRACE(__CTRACE_INPUT, "wgetch: curscr cury %d cury %d curscr curx %d curx %d\n",
 			_cursesi_screen->curscr->cury, win->begy + win->cury,

>Release-Note:

>Audit-Trail:
From: "Valeriy E. Ushakov" <uwe@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55457 CVS commit: src/lib/libcurses
Date: Mon, 6 Jul 2020 23:33:38 +0000

 Module Name:	src
 Committed By:	uwe
 Date:		Mon Jul  6 23:33:38 UTC 2020

 Modified Files:
 	src/lib/libcurses: get_wch.c getch.c

 Log Message:
 Pads are not to be automatically refreshed on input.

 X/Open Curses says in the documentation for newpad():

   Automatic refreshes of pads (e.g., from scrolling or echoing of
   input) do not occur.

 And in the documentation for get*():

   If the current or specified window is not a pad, and it has been
   moved or modified since the last refresh operation, then it will be
   refreshed before another character is read.

 From Michael Forney in PR lib/55457


 To generate a diff of this commit:
 cvs rdiff -u -r1.23 -r1.24 src/lib/libcurses/get_wch.c
 cvs rdiff -u -r1.74 -r1.75 src/lib/libcurses/getch.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->pending-pullups
State-Changed-By: uwe@NetBSD.org
State-Changed-When: Mon, 06 Jul 2020 23:43:05 +0000
State-Changed-Why:
Pullups requested for -8 and -9.


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55457 CVS commit: [netbsd-9] src/lib/libcurses
Date: Tue, 7 Jul 2020 12:51:19 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Jul  7 12:51:19 UTC 2020

 Modified Files:
 	src/lib/libcurses [netbsd-9]: get_wch.c getch.c

 Log Message:
 Pull up following revision(s) (requested by uwe in ticket #987):

 	lib/libcurses/get_wch.c: revision 1.24
 	lib/libcurses/getch.c: revision 1.75

 Pads are not to be automatically refreshed on input.

 X/Open Curses says in the documentation for newpad():
   Automatic refreshes of pads (e.g., from scrolling or echoing of
   input) do not occur.

 And in the documentation for get*():
   If the current or specified window is not a pad, and it has been
   moved or modified since the last refresh operation, then it will be
   refreshed before another character is read.

 From Michael Forney in PR lib/55457


 To generate a diff of this commit:
 cvs rdiff -u -r1.23 -r1.23.2.1 src/lib/libcurses/get_wch.c
 cvs rdiff -u -r1.73 -r1.73.2.1 src/lib/libcurses/getch.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/55457 (libcurses: when passed a pad, wget_wch/wgetch calls
 wrefresh on the pad)
Date: Thu, 6 Aug 2020 22:30:05 +0300

 It's pulled up to -9, but not -8.  On 8 there are a few missing
 revisions that are part of a rather large changeset that is not pulled
 up to 8.

 -uwe

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Wed, 02 Aug 2023 15:43:04 +0000
State-Changed-Why:
fixed in HEAD (prior to 10 branch), pulled up to 9
(follow up if this matters for 8; at this point I'm guessing no)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.