Subject: lib/9917: curses dumps core by meta-char when keypad enabled
To: None <gnats-bugs@gnats.netbsd.org>
From: Atsushi Onoe <onoe@sm.sony.co.jp>
List: netbsd-bugs
Date: 04/17/2000 18:19:12
>Number:         9917
>Category:       lib
>Synopsis:       curses dumps core by meta-char when keypad enabled
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 17 18:20:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Atsushi Onoe
>Release:        Mon Apr 17 12:33:52 GMT 2000
>Organization:
>Environment:
System: NetBSD duplo.sm.sony.co.jp 1.4X NetBSD 1.4X (DUPLO) #7: Mon Apr 10 23:22:58 JST 2000 onoe@duplo.sm.sony.co.jp:/usr/obj/DUPLO i386

>Description:
	When keypad flag is set, getch() returns unexpected value for key
	input with bit 8 set.  It also sometimes dumps core.

>How-To-Repeat:
	compile and run the program.
	After typing 'ALT+a', 'e1' is expected but any other value or core
	dump message will be shown.

#include <curses.h>

main()
{
	int ch;

	initscr();
	keypad(stdscr, 1);
	ch = getch();
	endwin();
	printf("\n%02x\n", ch);
	exit(0);
}
>Fix:
	Attached seems to avoid the problem in my environment.

Index: lib/libcurses/getch.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libcurses/getch.c,v
retrieving revision 1.20
diff -u -r1.20 getch.c
--- getch.c	2000/04/17 12:25:46	1.20
+++ getch.c	2000/04/18 01:17:07
@@ -408,7 +408,7 @@
 			if (nchar == 0)
 				return ERR;	/* just in case we are nodelay
 						 * mode */
-			k = (wchar_t) c;
+			k = (wchar_t) (unsigned char)c;
 #ifdef DEBUG
 			__CTRACE("inkey (state normal) got '%s'\n", unctrl(k));
 #endif
@@ -445,7 +445,7 @@
 			if ((to || delay) && (__notimeout() == ERR))
 					return ERR;
 
-			k = (wchar_t) c;
+			k = (wchar_t) (unsigned char)c;
 #ifdef DEBUG
 			__CTRACE("inkey (state assembling) got '%s'\n", unctrl(k));
 #endif
>Release-Note:
>Audit-Trail:
>Unformatted: