NetBSD Problem Report #6223

Received: (qmail 7859 invoked from network); 1 Oct 1998 18:37:16 -0000
Message-Id: <199810011835.LAA03682@ratbert.ecst.csuchico.edu>
Date: Thu, 1 Oct 1998 11:35:57 -0700 (PDT)
From: tfsmiles@ecst.csuchico.edu
Reply-To: tfsmiles@ecst.csuchico.edu
To: gnats-bugs@gnats.netbsd.org
Subject: Curses subwin() SEGVs
X-Send-Pr-Version: 3.95

>Number:         6223
>Category:       lib
>Synopsis:       Curses subwin() SEGVs when used on widows smaller than stdscr.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    blymn
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 01 11:50:01 +0000 1998
>Closed-Date:    Tue May 16 12:29:56 +0000 2000
>Last-Modified:  Tue May 16 12:29:56 +0000 2000
>Originator:     Mike Kelly
>Release:        NetBSD-1.3.2 (GENERIC) <NetBSD-current source date>
>Organization:
CSU Chico

>Environment:

System: NetBSD ratbert 1.3.2 NetBSD 1.3.2 (GENERIC) #0: Fri May 15 12:41:16 CDT 1998 scottr@beech:/usr/src/sys/arch/hp300/compile/GENERIC hp300


>Description:

When a user creates a subwin() in the standard window (stdscr), it works fine.
However, when the subwin() function is called to make a sub window in a window
smaller than the termianl screen (stdscr), a SIGSEGV is recieved.  Since a sub
window shares the memory space of the parent window as much as possible,
subwin() calls __set_subwin() to figure out which parts are shared.
__set_subwin() does not correctly calculate the location of the screen immage
that is to be shared.  Speciffically, it does not subtract the offset of the
parent window from the edge of the screen.

>How-To-Repeat:

#include <curses.h>

int
main()
{
  WINDOW *win;
  initscr();
  win = newwin(12, 12, 10,10);
   subwin(win, 10, 10, 11,11);
  endwin();
  return 0;
}

>Fix:

Apply the following patch to src/lib/libcurses/newwin.c:
144,145c144,145
<               olp = orig->lines[i + win->begy];
<               lp->line = &olp->line[win->begx];
---
>               olp = orig->lines[i + win->begy - orig->begy];
>               lp->line = &olp->line[win->begx - orig->begx];

NOTE: subwin() is not the only function that calls __set_subwin().  I did not
explore mvwin(), refresh() or any other function that may call __set_subwin().
While I have experenced no problems with refresh() on my sub window, it may
be possible (though unlikely) that these functions will break in subtle ways
when this patch is applied.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: blymn 
State-Changed-When: Mon May 15 04:50:52 PDT 2000 
State-Changed-Why:  
blymn analysing the pr. 


Responsible-Changed-From-To: lib-bug-people->blymn 
Responsible-Changed-By: blymn 
Responsible-Changed-When: Mon May 15 04:50:52 PDT 2000 
Responsible-Changed-Why:  
being analysed. 

From: blymn@baesystems.com.au (Brett Lymn)
To: gnats-bugs@netbsd.org
Cc: tfsmiles@ecst.csuchico.edu
Subject: lib/6223
Date: Mon, 15 May 2000 21:33:58 +0930 (CST)

 I have had a look at this pr and the solution proposed is not
 correct.  The function subwin works as it should, you must specify the
 subwin starting coordinates relative to the upper left corner of
 stdscr NOT the window in which the subwin is being created.  This
 behaviour is specified by the Single Unix Specification v2.  The
 function that performs the behaviour you are expecting is called
 derwin and is now implemented in the netbsd-current curses library.

 Is it ok for me to close this problem off?

 -- 
 ===============================================================================
 Brett Lymn, Computer Systems Administrator, BAE SYSTEMS
 ===============================================================================



From: Mike Kelly <tfsmiles@ecst.csuchico.edu>
To: Brett Lymn <blymn@baesystems.com.au>
Cc: gnats-bugs@netbsd.org
Subject: Re: lib/6223
Date: Mon, 15 May 2000 12:08:25 -0700

 On Mon, May 15, 2000 at 09:33:58PM +0930, Brett Lymn wrote:
 > 
 > I have had a look at this pr and the solution proposed is not
 > correct.  The function subwin works as it should, you must specify the
 > subwin starting coordinates relative to the upper left corner of
 > stdscr NOT the window in which the subwin is being created.  This
 > behaviour is specified by the Single Unix Specification v2.  The
 > function that performs the behaviour you are expecting is called
 > derwin and is now implemented in the netbsd-current curses library.
 > 
 > Is it ok for me to close this problem off?
 > 

 Sadly, just over a year ago the drive on which this project lived melted,
 and I was unable to recover it.  Shortly after this, my monitor started
 shorting out and I was forced to retire the machine.

 Since I have no way to examine what I was working on, nor test it again,
 you may close this problem report.

 Mike
 (:

 -- 
 --------TFSmiles@ecst.csuchico.edu-----------------The_glass_is_too_big--------
State-Changed-From-To: analyzed->closed 
State-Changed-By: blymn 
State-Changed-When: Tue May 16 05:20:53 PDT 2000 
State-Changed-Why:  
This bug looks to have been fixed. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.