From f486c68b1efe3bab5739c3f464fde6685a52bee5 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 17 Feb 2013 00:03:45 +0000 Subject: [PATCH] ncurses 5.9 - patch 20130216 + modify test/testcurs.c to work with mouse for ncurses as it does for pdcurses. + modify test/knight.c to work with mouse for pdcurses as it does for ncurses. + modify internal recursion in wgetch() which handles cooked mode to check if the call to wgetnstr() returned an error. This can happen when both nocbreak() and nodelay() are set, for instance (report by Nils Christopher Brause) (cf: 960418). + fixes for issues found by Coverity: + add a check for valid position in ClearToEOS() + fix in lib_twait.c when --enable-wgetch-events is used, pointer use after free. + improve a limit-check in make_hash.c + fix a memory leak in hashed_db.c --- NEWS | 18 +++++++++++++++++- dist.mk | 4 ++-- ncurses/base/lib_getch.c | 10 +++++----- ncurses/tinfo/hashed_db.c | 6 ++++-- ncurses/tinfo/make_hash.c | 4 ++-- ncurses/tty/lib_twait.c | 13 +++++++------ ncurses/tty/tty_update.c | 7 ++++++- package/debian/changelog | 4 ++-- package/ncurses.spec | 2 +- test/bs.c | 6 +++--- test/knight.c | 26 +++++++++++++++++++++++-- test/ncurses.c | 4 ++-- test/testcurs.c | 40 ++++++++++++++++++++++++++++++++++++--- 13 files changed, 112 insertions(+), 32 deletions(-) diff --git a/NEWS b/NEWS index e945c7fa..b32bdd39 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.2021 2013/02/09 22:39:26 tom Exp $ +-- $Id: NEWS,v 1.2023 2013/02/16 21:51:17 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,22 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20130216 + + modify test/testcurs.c to work with mouse for ncurses as it does for + pdcurses. + + modify test/knight.c to work with mouse for pdcurses as it does for + ncurses. + + modify internal recursion in wgetch() which handles cooked mode to + check if the call to wgetnstr() returned an error. This can happen + when both nocbreak() and nodelay() are set, for instance (report by + Nils Christopher Brause) (cf: 960418). + + fixes for issues found by Coverity: + + add a check for valid position in ClearToEOS() + + fix in lib_twait.c when --enable-wgetch-events is used, pointer + use after free. + + improve a limit-check in make_hash.c + + fix a memory leak in hashed_db.c + 20130209 + modify test/configure script to make it simpler to override names of curses-related libraries, to help with linking with pdcurses in diff --git a/dist.mk b/dist.mk index fdb69c5e..69b7443a 100644 --- a/dist.mk +++ b/dist.mk @@ -25,7 +25,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.913 2013/02/09 17:27:48 tom Exp $ +# $Id: dist.mk,v 1.914 2013/02/16 16:48:32 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -37,7 +37,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 5 NCURSES_MINOR = 9 -NCURSES_PATCH = 20130209 +NCURSES_PATCH = 20130216 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c index 575d112b..0a04ef5a 100644 --- a/ncurses/base/lib_getch.c +++ b/ncurses/base/lib_getch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. * + * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -42,7 +42,7 @@ #include -MODULE_ID("$Id: lib_getch.c,v 1.125 2012/08/04 17:11:37 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.126 2013/02/16 18:30:37 tom Exp $") #include @@ -439,11 +439,11 @@ _nc_wgetch(WINDOW *win, /* ungetch in reverse order */ #ifdef NCURSES_WGETCH_EVENTS rc = recur_wgetnstr(win, buf); - if (rc != KEY_EVENT) + if (rc != KEY_EVENT && rc != ERR) safe_ungetch(sp, '\n'); #else - (void) recur_wgetnstr(win, buf); - safe_ungetch(sp, '\n'); + if (recur_wgetnstr(win, buf) != ERR) + safe_ungetch(sp, '\n'); #endif for (bufp = buf + strlen(buf); bufp > buf; bufp--) safe_ungetch(sp, bufp[-1]); diff --git a/ncurses/tinfo/hashed_db.c b/ncurses/tinfo/hashed_db.c index 73045850..1b3eb97d 100644 --- a/ncurses/tinfo/hashed_db.c +++ b/ncurses/tinfo/hashed_db.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2006-2008,2011 Free Software Foundation, Inc. * + * Copyright (c) 2006-2011,2013 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -36,7 +36,7 @@ #if USE_HASHED_DB -MODULE_ID("$Id: hashed_db.c,v 1.15 2011/08/13 21:08:08 tom Exp $") +MODULE_ID("$Id: hashed_db.c,v 1.16 2013/02/16 21:50:03 tom Exp $") #if HASHED_DB_API >= 2 static DBC *cursor; @@ -105,6 +105,8 @@ make_connection(DB * db, const char *path, bool modify) if (p->path != 0) { p->next = connections; connections = p; + } else { + free(p); } } } diff --git a/ncurses/tinfo/make_hash.c b/ncurses/tinfo/make_hash.c index 83e8a688..31f21005 100644 --- a/ncurses/tinfo/make_hash.c +++ b/ncurses/tinfo/make_hash.c @@ -44,7 +44,7 @@ #include -MODULE_ID("$Id: make_hash.c,v 1.11 2013/01/26 22:00:11 tom Exp $") +MODULE_ID("$Id: make_hash.c,v 1.12 2013/02/16 21:27:50 tom Exp $") /* * _nc_make_hash_table() @@ -155,7 +155,7 @@ parse_columns(char *buffer) int col = 0; - if (list == 0 && (list = typeCalloc(char *, MAX_COLUMNS)) == 0) + if (list == 0 && (list = typeCalloc(char *, (MAX_COLUMNS + 1))) == 0) return (0); if (*buffer != '#') { diff --git a/ncurses/tty/lib_twait.c b/ncurses/tty/lib_twait.c index cb04679a..1d6cf10e 100644 --- a/ncurses/tty/lib_twait.c +++ b/ncurses/tty/lib_twait.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. * + * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -75,7 +75,7 @@ #endif #undef CUR -MODULE_ID("$Id: lib_twait.c,v 1.65 2012/10/27 20:42:47 tom Exp $") +MODULE_ID("$Id: lib_twait.c,v 1.66 2013/02/16 20:52:07 tom Exp $") static long _nc_gettime(TimeType * t0, int first) @@ -289,10 +289,6 @@ _nc_timed_wait(SCREEN *sp MAYBE_UNUSED, } } } - - if (fds != fd_list) - free((char *) fds); - #endif #elif defined(__BEOS__) @@ -505,5 +501,10 @@ _nc_timed_wait(SCREEN *sp MAYBE_UNUSED, result |= TW_EVENT; #endif +#ifdef NCURSES_WGETCH_EVENTS + if (fds != fd_list) + free((char *) fds); +#endif + return (result); } diff --git a/ncurses/tty/tty_update.c b/ncurses/tty/tty_update.c index 3253e549..3addd02e 100644 --- a/ncurses/tty/tty_update.c +++ b/ncurses/tty/tty_update.c @@ -82,7 +82,7 @@ #include -MODULE_ID("$Id: tty_update.c,v 1.275 2013/01/20 00:34:46 tom Exp $") +MODULE_ID("$Id: tty_update.c,v 1.276 2013/02/16 21:12:02 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -1118,6 +1118,11 @@ ClrToEOS(NCURSES_SP_DCLx NCURSES_CH_T blank) row = SP_PARM->_cursrow; col = SP_PARM->_curscol; + if (row < 0) + row = 0; + if (col < 0) + col = 0; + UpdateAttrs(SP_PARM, blank); TPUTS_TRACE("clr_eos"); NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx diff --git a/package/debian/changelog b/package/debian/changelog index c77c41d3..9b5d694c 100644 --- a/package/debian/changelog +++ b/package/debian/changelog @@ -1,8 +1,8 @@ -ncurses6 (5.9-20130209) unstable; urgency=low +ncurses6 (5.9-20130216) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 09 Feb 2013 12:28:44 -0500 + -- Thomas E. Dickey Sat, 16 Feb 2013 11:48:20 -0500 ncurses6 (5.9-20120608) unstable; urgency=low diff --git a/package/ncurses.spec b/package/ncurses.spec index b6d43343..61b51ffb 100644 --- a/package/ncurses.spec +++ b/package/ncurses.spec @@ -1,7 +1,7 @@ Summary: shared libraries for terminal handling Name: ncurses6 Release: 5.9 -Version: 20130209 +Version: 20130216 License: X11 Group: Development/Libraries Source: ncurses-%{release}-%{version}.tgz diff --git a/test/bs.c b/test/bs.c index ebcabc42..9a43e623 100644 --- a/test/bs.c +++ b/test/bs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc. * + * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -34,7 +34,7 @@ * v2.0 featuring strict ANSI/POSIX conformance, November 1993. * v2.1 with ncurses mouse support, September 1995 * - * $Id: bs.c,v 1.59 2012/12/16 00:20:49 tom Exp $ + * $Id: bs.c,v 1.60 2013/02/16 19:54:37 tom Exp $ */ #include @@ -956,7 +956,7 @@ cpufire(int x, int y) bool hit, sunk; ship_t *ss = NULL; - hit = board[PLAYER][x][y]; + hit = (bool) board[PLAYER][x][y]; hits[COMPUTER][x][y] = (hit ? MARK_HIT : MARK_MISS); MvPrintw(PROMPTLINE, 0, "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : diff --git a/test/knight.c b/test/knight.c index b1215fcc..ae9d2234 100644 --- a/test/knight.c +++ b/test/knight.c @@ -33,7 +33,7 @@ * Eric S. Raymond July 22 1995. Mouse support * added September 20th 1995. * - * $Id: knight.c,v 1.35 2013/02/03 00:16:59 tom Exp $ + * $Id: knight.c,v 1.36 2013/02/16 19:53:08 tom Exp $ */ #include @@ -130,6 +130,9 @@ init_program(void) #ifdef NCURSES_MOUSE_VERSION (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL); #endif /* NCURSES_MOUSE_VERSION */ +#if defined(PDCURSES) + mouse_set(BUTTON1_RELEASED); +#endif oldch = minus; } @@ -577,8 +580,9 @@ play(void) nx = col + 1; break; -#ifdef NCURSES_MOUSE_VERSION +#ifdef KEY_MOUSE case KEY_MOUSE: +#ifdef NCURSES_MOUSE_VERSION { MEVENT myevent; @@ -595,6 +599,24 @@ play(void) } } #endif /* NCURSES_MOUSE_VERSION */ +#ifdef PDCURSES + { + int test_y, test_x; + request_mouse_pos(); + test_y = MOUSE_Y_POS + 0; + test_x = MOUSE_X_POS + 1; + if (test_y >= CY(0) && test_y <= CY(BDEPTH) + && test_x >= CX(0) && test_x <= CX(BWIDTH)) { + ny = CYINV(test_y); + nx = CXINV(test_x); + wmove(helpwin, 0, 0); + wrefresh(helpwin); + ungetch('\n'); + } + break; + } +#endif /* PDCURSES */ +#endif /* KEY_MOUSE */ case KEY_B2: case '\n': diff --git a/test/ncurses.c b/test/ncurses.c index b18205dc..cea9090f 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.387 2013/01/13 00:40:17 tom Exp $ +$Id: ncurses.c,v 1.388 2013/02/16 18:56:30 tom Exp $ ***************************************************************************/ @@ -6922,7 +6922,7 @@ main(int argc, char *argv[]) bkgdset(BLANK); /* tests, in general, will want these modes */ - use_colors = monochrome ? FALSE : has_colors(); + use_colors = (bool) (monochrome ? FALSE : has_colors()); if (use_colors) { start_color(); diff --git a/test/testcurs.c b/test/testcurs.c index 8310f3f8..579b9977 100644 --- a/test/testcurs.c +++ b/test/testcurs.c @@ -6,7 +6,7 @@ * wrs(5/28/93) -- modified to be consistent (perform identically) with either * PDCurses or under Unix System V, R4 * - * $Id: testcurs.c,v 1.46 2012/11/24 19:38:20 tom Exp $ + * $Id: testcurs.c,v 1.47 2013/02/16 20:29:04 tom Exp $ */ #include @@ -341,6 +341,9 @@ inputTest(WINDOW *win) typeahead(-1); #endif +#ifdef NCURSES_MOUSE_VERSION + mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); +#endif #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif @@ -355,8 +358,38 @@ inputTest(WINDOW *win) wprintw(win, "Key Pressed: %c", c); else wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); -#if defined(PDCURSES) +#ifdef KEY_MOUSE +#define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037)) +#define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)) +#define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)) +#define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)) +#define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)) if (c == KEY_MOUSE) { + MEVENT event; + int button = 0; + + getmouse(&event); + if (ButtonChanged(1)) + button = 1; + else if (ButtonChanged(2)) + button = 2; + else if (ButtonChanged(3)) + button = 3; + else + button = 0; + wmove(win, 4, 18); + wprintw(win, "Button %d: ", button); + if (ButtonPressed(button)) + wprintw(win, "pressed: "); + else if (ButtonDouble(button)) + wprintw(win, "double: "); + else if (ButtonTriple(button)) + wprintw(win, "triple: "); + else + wprintw(win, "released: "); + wprintw(win, " Position: Y: %d X: %d", event.y, event.x); +#if defined(NCURSES_MOUSE_VERSION) +#elif defined(PDCURSES) int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) @@ -378,8 +411,9 @@ inputTest(WINDOW *win) else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); +#endif /* PDCURSES */ } -#endif +#endif /* KEY_MOUSE */ wrefresh(win); if (c == ' ') break; -- 2.44.0