From 8f527f87c0b979d9c2598ef5c3394463af288468 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Tue, 5 Aug 2008 01:06:16 +0000 Subject: [PATCH] ncurses 5.6 - patch 20080804 + modify _nc_panelhook() data to account for a permanent memory leak. + fix memory leaks in test/demo_menus + fix most warnings from Klocwork tool (report by Larry Zhou). + modify configure script CF_XOPEN_SOURCE macro to add case for "dragonfly" from xterm #236 changes. + modify configure script --with-hashed-db to let $LIBS override the search for the db library (prompted by report by Samson Pierre). --- NEWS | 11 +- aclocal.m4 | 10 +- c++/cursespad.cc | 5 +- c++/demo.cc | 7 +- configure | 4 +- dist.mk | 4 +- form/frm_def.c | 16 +- include/capdefaults.c | 14 +- include/nc_panel.h | 11 +- menu/m_driver.c | 6 +- misc/ncu-indent | 6 +- ncurses/base/lib_freeall.c | 5 +- ncurses/base/lib_getch.c | 36 ++-- ncurses/base/lib_newterm.c | 3 +- ncurses/base/lib_set_term.c | 12 +- ncurses/base/lib_slkrefr.c | 6 +- ncurses/curses.priv.h | 4 +- ncurses/tinfo/captoinfo.c | 11 +- ncurses/tinfo/comp_scan.c | 93 ++++++---- ncurses/tinfo/home_terminfo.c | 12 +- ncurses/tinfo/lib_acs.c | 7 +- ncurses/tinfo/lib_setup.c | 18 +- ncurses/tinfo/lib_tparm.c | 12 +- ncurses/tinfo/lib_ttyflags.c | 8 +- ncurses/tinfo/make_keys.c | 18 +- ncurses/tinfo/name_match.c | 27 +-- ncurses/tinfo/parse_entry.c | 22 ++- ncurses/tinfo/read_entry.c | 4 +- ncurses/tinfo/write_entry.c | 20 ++- ncurses/trace/lib_trace.c | 7 +- ncurses/trace/lib_traceatr.c | 268 +++++++++++++++-------------- ncurses/trace/lib_tracebits.c | 81 ++++----- ncurses/trace/lib_tracechr.c | 4 +- ncurses/trace/lib_tracedmp.c | 6 +- ncurses/trace/lib_tracemse.c | 4 +- ncurses/trace/trace_buf.c | 51 +++--- ncurses/trace/trace_tries.c | 6 +- ncurses/trace/varargs.c | 6 +- ncurses/trace/visbuf.c | 180 ++++++++++--------- ncurses/tty/hardscroll.c | 19 +- panel/p_new.c | 9 +- progs/dump_entry.c | 67 ++++---- progs/infocmp.c | 85 ++++----- progs/progs.priv.h | 5 +- progs/tic.c | 84 +++++---- progs/toe.c | 21 ++- progs/tset.c | 36 ++-- test/blue.c | 5 +- test/bs.c | 4 +- test/cardfile.c | 5 +- test/demo_defkey.c | 3 +- test/demo_forms.c | 46 ++--- test/demo_menus.c | 40 +++-- test/demo_panels.c | 30 ++-- test/ditto.c | 18 +- test/gdc.c | 18 +- test/hanoi.c | 30 ++-- test/knight.c | 6 +- test/ncurses.c | 314 ++++++++++++++++++---------------- test/newdemo.c | 3 +- test/testcurs.c | 78 +++++---- test/view.c | 10 +- test/xmas.c | 82 ++++----- 63 files changed, 1148 insertions(+), 895 deletions(-) diff --git a/NEWS b/NEWS index 9ed4a8a9..d554a553 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.1256 2008/07/26 19:33:40 tom Exp $ +-- $Id: NEWS,v 1.1261 2008/08/04 18:22:11 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,15 @@ 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. +20080804 + + modify _nc_panelhook() data to account for a permanent memory leak. + + fix memory leaks in test/demo_menus + + fix most warnings from Klocwork tool (report by Larry Zhou). + + modify configure script CF_XOPEN_SOURCE macro to add case for + "dragonfly" from xterm #236 changes. + + modify configure script --with-hashed-db to let $LIBS override the + search for the db library (prompted by report by Samson Pierre). + 20080726 + build-fixes for gcc 4.3.1 (changes to gnat "warnings", and C inlining thresholds). diff --git a/aclocal.m4 b/aclocal.m4 index a37d3c3a..0c15200e 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -28,7 +28,7 @@ dnl*************************************************************************** dnl dnl Author: Thomas E. Dickey 1995-on dnl -dnl $Id: aclocal.m4,v 1.450 2008/07/26 21:57:19 tom Exp $ +dnl $Id: aclocal.m4,v 1.451 2008/08/04 10:26:11 tom Exp $ dnl Macros used in NCURSES auto-configuration script. dnl dnl These macros are maintained separately from NCURSES. The copyright on @@ -1715,7 +1715,7 @@ fi ]) ])dnl dnl --------------------------------------------------------------------------- -dnl CF_HASHED_DB_LIBS version: 7 updated: 2007/12/01 15:01:37 +dnl CF_HASHED_DB_LIBS version: 8 updated: 2008/08/04 06:18:06 dnl ----------------- dnl Given that we have the header and version for hashed database, find the dnl library information. @@ -1723,7 +1723,7 @@ AC_DEFUN([CF_HASHED_DB_LIBS], [ AC_CACHE_CHECK(for db libraries, cf_cv_hashed_db_libs,[ cf_cv_hashed_db_libs=unknown -for cf_db_libs in db$cf_cv_hashed_db_version db-$cf_cv_hashed_db_version db '' +for cf_db_libs in "" db$cf_cv_hashed_db_version db-$cf_cv_hashed_db_version db '' do cf_save_libs="$LIBS" if test -n "$cf_db_libs"; then @@ -5228,7 +5228,7 @@ CF_NO_LEAKS_OPTION(valgrind, [USE_VALGRIND]) ])dnl dnl --------------------------------------------------------------------------- -dnl CF_XOPEN_SOURCE version: 25 updated: 2007/01/29 18:36:38 +dnl CF_XOPEN_SOURCE version: 26 updated: 2008/07/27 11:26:57 dnl --------------- dnl Try to get _XOPEN_SOURCE defined properly that we can use POSIX functions, dnl or adapt to the vendor's definitions to get equivalent functionality, @@ -5248,7 +5248,7 @@ case $host_os in #(vi aix[[45]]*) #(vi CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE" ;; -freebsd*) #(vi +freebsd*|dragonfly*) #(vi # 5.x headers associate # _XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L # _XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L diff --git a/c++/cursespad.cc b/c++/cursespad.cc index 3685c5e5..28c58fab 100644 --- a/c++/cursespad.cc +++ b/c++/cursespad.cc @@ -1,6 +1,6 @@ // * this is for making emacs happy: -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 @@ #include #include -MODULE_ID("$Id: cursespad.cc,v 1.12 2007/04/07 18:43:54 tom Exp $") +MODULE_ID("$Id: cursespad.cc,v 1.13 2008/08/04 18:59:22 tom Exp $") NCursesPad::NCursesPad(int nlines, int ncols) : NCursesWindow(), @@ -212,6 +212,7 @@ void NCursesPad::setSubWindow(NCursesWindow& sub) { if (static_cast(0) == viewWin) err_handler("Pad has no viewport"); + assert(viewWin != 0); if (!viewWin->isDescendant(sub)) THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR)); viewSub = ⊂ diff --git a/c++/demo.cc b/c++/demo.cc index 8fa19ad2..ddd5f2b3 100644 --- a/c++/demo.cc +++ b/c++/demo.cc @@ -1,6 +1,6 @@ // * This makes emacs happy -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -35,7 +35,7 @@ * Demo code for NCursesMenu and NCursesForm written by * Juergen Pfeifer * - * $Id: demo.cc,v 1.36 2007/04/07 20:24:49 tom Exp $ + * $Id: demo.cc,v 1.38 2008/08/04 17:16:57 tom Exp $ */ #include "internal.h" @@ -312,6 +312,7 @@ public: Soft_Label_Key_Set* S = new Soft_Label_Key_Set; for(int i=1; i <= S->labels(); i++) { char buf[8]; + assert(i < 100); ::sprintf(buf, "Frm%02d", i); (*S)[i] = buf; // Text (*S)[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification @@ -319,6 +320,7 @@ public: NCursesApplication::getApplication()->push(*S); F(); NCursesApplication::getApplication()->pop(); + delete S; return FALSE; } }; @@ -530,6 +532,7 @@ void TestApplication::init_labels(Soft_Label_Key_Set& S) const { for(int i=1; i <= S.labels(); i++) { char buf[8]; + assert(i < 100); ::sprintf(buf, "Key%02d", i); S[i] = buf; // Text S[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification diff --git a/configure b/configure index 890a9d36..0eee83a2 100755 --- a/configure +++ b/configure @@ -6178,7 +6178,7 @@ case $host_os in #(vi aix[45]*) #(vi CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE" ;; -freebsd*) #(vi +freebsd*|dragonfly*) #(vi # 5.x headers associate # _XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L # _XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L @@ -13937,7 +13937,7 @@ if test "${cf_cv_hashed_db_libs+set}" = set; then else cf_cv_hashed_db_libs=unknown -for cf_db_libs in db$cf_cv_hashed_db_version db-$cf_cv_hashed_db_version db '' +for cf_db_libs in "" db$cf_cv_hashed_db_version db-$cf_cv_hashed_db_version db '' do cf_save_libs="$LIBS" if test -n "$cf_db_libs"; then diff --git a/dist.mk b/dist.mk index 43fbf143..a17315de 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.652 2008/07/26 17:36:20 tom Exp $ +# $Id: dist.mk,v 1.654 2008/08/04 23:50:26 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 = 6 -NCURSES_PATCH = 20080726 +NCURSES_PATCH = 20080804 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/form/frm_def.c b/form/frm_def.c index c2044a39..e6897514 100644 --- a/form/frm_def.c +++ b/form/frm_def.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -32,7 +32,7 @@ #include "form.priv.h" -MODULE_ID("$Id: frm_def.c,v 1.22 2007/10/13 19:31:17 tom Exp $") +MODULE_ID("$Id: frm_def.c,v 1.23 2008/08/04 00:07:55 tom Exp $") /* this can't be readonly */ static FORM default_form = @@ -234,8 +234,16 @@ Connect_Fields(FORM *form, FIELD **fields) fields[j]->page = page_nr; fld = Insert_Field_By_Position(fields[j], fld); } - form->page[page_nr].smin = fld->index; - form->page[page_nr].smax = fld->sprev->index; + if (fld) + { + form->page[page_nr].smin = fld->index; + form->page[page_nr].smax = fld->sprev->index; + } + else + { + form->page[page_nr].smin = 0; + form->page[page_nr].smax = 0; + } } RETURN(E_OK); } diff --git a/include/capdefaults.c b/include/capdefaults.c index 071f9e17..33f2fe8f 100644 --- a/include/capdefaults.c +++ b/include/capdefaults.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2008 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 * @@ -29,9 +29,10 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ -/* $Id: capdefaults.c,v 1.12 2000/01/02 02:34:56 tom Exp $ */ +/* $Id: capdefaults.c,v 1.13 2008/08/04 12:33:42 tom Exp $ */ /* * Compute obsolete capabilities. The reason this is an include file is @@ -44,9 +45,10 @@ */ { char *sp; - int capval; + short capval; -#define EXTRACT_DELAY(str) (sp = strchr(str, '*'), sp ? atoi(sp+1) : 0) +#define EXTRACT_DELAY(str) \ + (short) (sp = strchr(str, '*'), sp ? atoi(sp+1) : 0) /* current (4.4BSD) capabilities marked obsolete */ if (VALID_STRING(carriage_return) @@ -73,8 +75,8 @@ magic_cookie_glitch_ul = magic_cookie_glitch; /* totally obsolete capabilities */ - linefeed_is_newline = VALID_STRING(newline) - && (strcmp("\n", newline) == 0); + linefeed_is_newline = (char) (VALID_STRING(newline) + && (strcmp("\n", newline) == 0)); if (VALID_STRING(cursor_left) && (capval = EXTRACT_DELAY(cursor_left))) backspace_delay = capval; diff --git a/include/nc_panel.h b/include/nc_panel.h index bb1f6745..6578577e 100644 --- a/include/nc_panel.h +++ b/include/nc_panel.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2000,2008 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 * @@ -27,13 +27,13 @@ ****************************************************************************/ /**************************************************************************** - * Author: Zeyd M. Ben-Halim 1992,1995 * - * and: Eric S. Raymond * + * Author: Juergen Pfeifer 1997 * + * and: Thomas E. Dickey * ****************************************************************************/ /* - * $Id: nc_panel.h,v 1.3 2000/12/10 02:04:35 tom Exp $ + * $Id: nc_panel.h,v 1.5 2008/08/04 18:26:46 tom Exp $ * * nc_panel.h * @@ -54,6 +54,9 @@ struct panelhook { struct panel* top_panel; struct panel* bottom_panel; struct panel* stdscr_pseudo_panel; +#if NO_LEAKS + int (*destroy)(struct panel *); +#endif }; /* Retrieve the panelhook of the current screen */ diff --git a/menu/m_driver.c b/menu/m_driver.c index 27f9fbad..d418e6a2 100644 --- a/menu/m_driver.c +++ b/menu/m_driver.c @@ -37,7 +37,7 @@ #include "menu.priv.h" -MODULE_ID("$Id: m_driver.c,v 1.26 2008/07/05 20:54:33 tom Exp $") +MODULE_ID("$Id: m_driver.c,v 1.27 2008/08/03 22:08:22 tom Exp $") /* Macros */ @@ -303,7 +303,7 @@ menu_driver(MENU * menu, int c) else { my_top_row += rdiff; - while (rdiff-- > 0 && item != (ITEM *) 0) + while (rdiff-- > 0 && item != 0 && item->down != 0) item = item->down; } break; @@ -316,7 +316,7 @@ menu_driver(MENU * menu, int c) else { my_top_row -= rdiff; - while (rdiff-- && item != (ITEM *) 0) + while (rdiff-- > 0 && item != 0 && item->up != 0) item = item->up; } break; diff --git a/misc/ncu-indent b/misc/ncu-indent index 1e1c7fff..862a108a 100755 --- a/misc/ncu-indent +++ b/misc/ncu-indent @@ -1,6 +1,6 @@ #!/bin/sh #**************************************************************************** -#* Copyright (c) 2001-2005,2006 Thomas E. Dickey * +#* Copyright (c) 2001-2006,2008 Thomas E. Dickey * #* * #* Permission is hereby granted, free of charge, to any person obtaining a * #* copy of this software and associated documentation files (the * @@ -26,7 +26,7 @@ #* sale, use or other dealings in this Software without prior written * #* authorization. * #****************************************************************************/ -# $Id: ncu-indent,v 1.16 2006/02/18 17:02:22 tom Exp $ +# $Id: ncu-indent,v 1.17 2008/08/03 15:46:44 tom Exp $ NOOP=no OPTS=' --blank-lines-after-procedures @@ -87,6 +87,7 @@ do rm -f "$save" "$test" mv "$name" "$save" sed \ + -e '/EMPTY_MODULE(/s/)$/);/' \ -e '/MODULE_ID(/s/)$/);/' \ -e 's,\_oldnum_list != 0) { FreeAndNull(SP->_oldnum_list); } + if (SP->_panelHook.destroy != 0) { + SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel); + } } #endif if (SP != 0) { diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c index 56e2a3a8..c7ca7aaa 100644 --- a/ncurses/base/lib_getch.c +++ b/ncurses/base/lib_getch.c @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_getch.c,v 1.96 2008/06/28 23:29:20 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.97 2008/08/03 22:56:42 tom Exp $") #include @@ -284,23 +284,27 @@ recur_wgetnstr(WINDOW *win, char *buf) SCREEN *sp = _nc_screen_of(win); int rc; + if (sp != 0) { #ifdef USE_PTHREADS - if (sp != SP) { - SCREEN *save_SP; - - /* temporarily switch to the window's screen to get cooked input */ - _nc_lock_global(curses); - save_SP = SP; - _nc_set_screen(sp); - rc = recur_wgetnstr(win, buf); - _nc_set_screen(save_SP); - _nc_unlock_global(curses); - } else + if (sp != SP) { + SCREEN *save_SP; + + /* temporarily switch to the window's screen to get cooked input */ + _nc_lock_global(curses); + save_SP = SP; + _nc_set_screen(sp); + rc = recur_wgetnstr(win, buf); + _nc_set_screen(save_SP); + _nc_unlock_global(curses); + } else #endif - { - sp->_called_wgetch = TRUE; - rc = wgetnstr(win, buf, MAXCOLUMNS); - sp->_called_wgetch = FALSE; + { + sp->_called_wgetch = TRUE; + rc = wgetnstr(win, buf, MAXCOLUMNS); + sp->_called_wgetch = FALSE; + } + } else { + rc = ERR; } return rc; } diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c index 3e6034c2..c467a608 100644 --- a/ncurses/base/lib_newterm.c +++ b/ncurses/base/lib_newterm.c @@ -48,7 +48,7 @@ #include /* clear_screen, cup & friends, cur_term */ #include -MODULE_ID("$Id: lib_newterm.c,v 1.71 2008/06/21 20:55:11 tom Exp $") +MODULE_ID("$Id: lib_newterm.c,v 1.72 2008/08/03 22:49:49 tom Exp $") #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 @@ -158,6 +158,7 @@ newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) _nc_set_screen(current); result = 0; } else { + assert(SP != 0); /* * In setupterm() we did a set_curterm(), but it was before we set * SP. So the "current" screen's terminal pointer was overwritten diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c index 6fbf6ad7..aff432bb 100644 --- a/ncurses/base/lib_set_term.c +++ b/ncurses/base/lib_set_term.c @@ -44,7 +44,7 @@ #include /* cur_term */ #include -MODULE_ID("$Id: lib_set_term.c,v 1.115 2008/06/28 15:33:52 tom Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.117 2008/08/04 18:11:12 tom Exp $") NCURSES_EXPORT(SCREEN *) set_term(SCREEN *screenp) @@ -359,11 +359,10 @@ _nc_setupscreen(int slines GCC_UNUSED, * Allow those assumed/default color assumptions to be overridden at * runtime: */ - if (getenv("NCURSES_ASSUMED_COLORS") != 0) { - char *p = getenv("NCURSES_ASSUMED_COLORS"); + if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) { int fg, bg; char sep1, sep2; - int count = sscanf(p, "%d%c%d%c", &fg, &sep1, &bg, &sep2); + int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2); if (count >= 1) { SP->_default_fg = (fg >= 0 && fg < max_colors) ? fg : C_MASK; if (count >= 3) { @@ -419,11 +418,6 @@ _nc_setupscreen(int slines GCC_UNUSED, SP->_mouse_wrap = no_mouse_wrap; SP->_mouse_fd = -1; - /* initialize the panel hooks */ - SP->_panelHook.top_panel = (struct panel *) 0; - SP->_panelHook.bottom_panel = (struct panel *) 0; - SP->_panelHook.stdscr_pseudo_panel = (struct panel *) 0; - /* * If we've no magic cookie support, we suppress attributes that xmc would * affect, i.e., the attributes that affect the rendition of a space. diff --git a/ncurses/base/lib_slkrefr.c b/ncurses/base/lib_slkrefr.c index c8ca28b9..20a2198e 100644 --- a/ncurses/base/lib_slkrefr.c +++ b/ncurses/base/lib_slkrefr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 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 * @@ -40,7 +40,7 @@ #include #include /* num_labels, label_*, plab_norm */ -MODULE_ID("$Id: lib_slkrefr.c,v 1.15 2006/11/25 22:32:15 tom Exp $") +MODULE_ID("$Id: lib_slkrefr.c,v 1.16 2008/08/03 22:40:27 tom Exp $") /* * Write the soft labels to the soft-key window. @@ -61,7 +61,7 @@ slk_intern_refresh(SLK * slk) } } else { wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x); - if (SP && SP->_slk) { + if (SP->_slk) { wattrset(slk->win, AttrOf(SP->_slk->attr)); } waddstr(slk->win, slk->ent[i].form_text); diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index c6fda33d..5a39028f 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -34,7 +34,7 @@ /* - * $Id: curses.priv.h,v 1.386 2008/06/28 15:27:47 tom Exp $ + * $Id: curses.priv.h,v 1.387 2008/08/03 15:39:29 tom Exp $ * * curses.priv.h * @@ -1307,7 +1307,7 @@ extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int); extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int); -#define empty_module(name) \ +#define EMPTY_MODULE(name) \ extern NCURSES_EXPORT(void) name (void); \ NCURSES_EXPORT(void) name (void) { } diff --git a/ncurses/tinfo/captoinfo.c b/ncurses/tinfo/captoinfo.c index 0e3baa84..ef68b04d 100644 --- a/ncurses/tinfo/captoinfo.c +++ b/ncurses/tinfo/captoinfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 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 * @@ -93,7 +93,7 @@ #include #include -MODULE_ID("$Id: captoinfo.c,v 1.49 2006/12/16 19:16:53 tom Exp $") +MODULE_ID("$Id: captoinfo.c,v 1.51 2008/08/03 18:35:47 tom Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ @@ -149,7 +149,7 @@ static void push(void) /* push onstack on to the stack */ { - if (stackptr > MAX_PUSHED) + if (stackptr >= MAX_PUSHED) _nc_warning("string too complex to convert"); else stack[stackptr++] = onstack; @@ -788,6 +788,11 @@ _nc_infotocap(const char *cap GCC_UNUSED, const char *str, int const parameteriz } /* endswitch (*str) */ } /* endelse (*str == '%') */ + /* + * 'str' always points to the end of what was scanned in this step, + * but that may not be the end of the string. + */ + assert(str != 0); if (*str == '\0') break; diff --git a/ncurses/tinfo/comp_scan.c b/ncurses/tinfo/comp_scan.c index e937f7eb..140960a8 100644 --- a/ncurses/tinfo/comp_scan.c +++ b/ncurses/tinfo/comp_scan.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 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 * @@ -51,7 +51,7 @@ #include #include -MODULE_ID("$Id: comp_scan.c,v 1.78 2006/12/16 19:17:01 tom Exp $") +MODULE_ID("$Id: comp_scan.c,v 1.82 2008/08/04 20:25:03 tom Exp $") /* * Maximum length of string capability we'll accept before raising an error. @@ -203,6 +203,7 @@ next_char(void) result = typeRealloc(char, allocated, result); if (result == 0) return (EOF); + bufstart = result; } if (used == 0) _nc_curr_file_pos = ftell(yyin); @@ -293,6 +294,15 @@ eat_escaped_newline(int ch) return ch; } +#define TOK_BUF_SIZE MAX_ENTRY_SIZE + +#define OkToAdd() \ + ((tok_ptr - tok_buf) < (TOK_BUF_SIZE - 2)) + +#define AddCh(ch) \ + *tok_ptr++ = ch; \ + *tok_ptr = '\0' + /* * int * get_token() @@ -330,12 +340,12 @@ NCURSES_EXPORT(int) _nc_get_token(bool silent) { static const char terminfo_punct[] = "@%&*!#"; - static char *buffer; + static char *tok_buf; char *after_list; char *after_name; char *numchk; - char *ptr; + char *tok_ptr; char *s; char numbuf[80]; int ch; @@ -367,10 +377,10 @@ _nc_get_token(bool silent) if (end_of_stream()) { yyin = 0; next_char(); /* frees its allocated memory */ - if (buffer != 0) { - if (_nc_curr_token.tk_name == buffer) + if (tok_buf != 0) { + if (_nc_curr_token.tk_name == tok_buf) _nc_curr_token.tk_name = 0; - FreeAndNull(buffer); + FreeAndNull(tok_buf); } return (EOF); } @@ -426,15 +436,15 @@ _nc_get_token(bool silent) goto start_token; } - if (buffer == 0) - buffer = typeMalloc(char, MAX_ENTRY_SIZE); + if (tok_buf == 0) + tok_buf = typeMalloc(char, TOK_BUF_SIZE); #ifdef TRACE old_line = _nc_curr_line; old_col = _nc_curr_col; #endif - ptr = buffer; - *(ptr++) = ch; + tok_ptr = tok_buf; + AddCh(ch); if (first_column) { _nc_comment_start = token_start; @@ -448,9 +458,9 @@ _nc_get_token(bool silent) if (ch == EOF) { _nc_err_abort(MSG_NO_INPUTS); } else if (ch == '|') { - after_list = ptr; + after_list = tok_ptr; if (after_name == 0) - after_name = ptr; + after_name = tok_ptr; } else if (ch == ':' && last_char() != ',') { _nc_syntax = SYN_TERMCAP; separator = ':'; @@ -474,9 +484,14 @@ _nc_get_token(bool silent) } else ch = eat_escaped_newline(ch); - *ptr++ = ch; + if (OkToAdd()) { + AddCh(ch); + } else { + ch = EOF; + break; + } } - ptr[0] = '\0'; + *tok_ptr = '\0'; if (_nc_syntax == ERR) { /* * Grrr...what we ought to do here is barf, complaining that @@ -488,9 +503,11 @@ _nc_get_token(bool silent) separator = ':'; } else if (_nc_syntax == SYN_TERMINFO) { /* throw away trailing /, *$/ */ - for (--ptr; iswhite(*ptr) || *ptr == ','; ptr--) + for (--tok_ptr; + iswhite(*tok_ptr) || *tok_ptr == ','; + tok_ptr--) continue; - ptr[1] = '\0'; + tok_ptr[1] = '\0'; } /* @@ -501,7 +518,7 @@ _nc_get_token(bool silent) if (after_name != 0) { ch = *after_name; *after_name = '\0'; - _nc_set_type(buffer); + _nc_set_type(tok_buf); *after_name = ch; } @@ -517,7 +534,7 @@ _nc_get_token(bool silent) _nc_warning("older tic versions may treat the description field as an alias"); } } else { - after_list = buffer + strlen(buffer); + after_list = tok_buf + strlen(tok_buf); DEBUG(1, ("missing description")); } @@ -526,7 +543,7 @@ _nc_get_token(bool silent) * rdist and some termcap tools. Slashes are a no-no. Other * special characters can be dangerous due to shell expansion. */ - for (s = buffer; s < after_list; ++s) { + for (s = tok_buf; s < after_list; ++s) { if (isspace(UChar(*s))) { if (!silent) _nc_warning("whitespace in name or alias field"); @@ -542,7 +559,7 @@ _nc_get_token(bool silent) } } - _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_name = tok_buf; type = NAMES; } else { if (had_newline && _nc_syntax == SYN_TERMCAP) { @@ -559,23 +576,28 @@ _nc_get_token(bool silent) break; } } - *(ptr++) = ch; + if (OkToAdd()) { + AddCh(ch); + } else { + ch = EOF; + break; + } } - *ptr++ = '\0'; + *tok_ptr++ = '\0'; /* separate name/value in buffer */ switch (ch) { case ',': case ':': if (ch != separator) _nc_err_abort("Separator inconsistent with syntax"); - _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_name = tok_buf; type = BOOLEAN; break; case '@': if ((ch = next_char()) != separator && !silent) _nc_warning("Missing separator after `%s', have %s", - buffer, unctrl((chtype) ch)); - _nc_curr_token.tk_name = buffer; + tok_buf, unctrl((chtype) ch)); + _nc_curr_token.tk_name = tok_buf; type = CANCEL; break; @@ -590,21 +612,21 @@ _nc_get_token(bool silent) number = strtol(numbuf, &numchk, 0); if (!silent) { if (numchk == numbuf) - _nc_warning("no value given for `%s'", buffer); + _nc_warning("no value given for `%s'", tok_buf); if ((*numchk != '\0') || (ch != separator)) _nc_warning("Missing separator"); } - _nc_curr_token.tk_name = buffer; + _nc_curr_token.tk_name = tok_buf; _nc_curr_token.tk_valnumber = number; type = NUMBER; break; case '=': - ch = _nc_trans_string(ptr, buffer + MAX_ENTRY_SIZE); + ch = _nc_trans_string(tok_ptr, tok_buf + TOK_BUF_SIZE); if (!silent && ch != separator) _nc_warning("Missing separator"); - _nc_curr_token.tk_name = buffer; - _nc_curr_token.tk_valstring = ptr; + _nc_curr_token.tk_name = tok_buf; + _nc_curr_token.tk_valstring = tok_ptr; type = STRING; break; @@ -713,8 +735,15 @@ _nc_trans_string(char *ptr, char *last) bool long_warning = FALSE; while ((ch = c = next_char()) != (chtype) separator && c != EOF) { - if (ptr == (last - 1)) + if (ptr >= (last - 1)) { + if (c != EOF) { + while ((c = next_char()) != separator && c != EOF) { + ; + } + ch = c; + } break; + } if ((_nc_syntax == SYN_TERMCAP) && c == '\n') break; if (ch == '^' && last_ch != '%') { diff --git a/ncurses/tinfo/home_terminfo.c b/ncurses/tinfo/home_terminfo.c index 92c26705..4521c4a8 100644 --- a/ncurses/tinfo/home_terminfo.c +++ b/ncurses/tinfo/home_terminfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -37,9 +37,7 @@ #include #include -MODULE_ID("$Id: home_terminfo.c,v 1.10 2007/04/21 23:11:53 tom Exp $") - -#define my_length (strlen(home) + sizeof(PRIVATE_INFO)) +MODULE_ID("$Id: home_terminfo.c,v 1.11 2008/08/03 23:43:11 tom Exp $") /* ncurses extension...fall back on user's private directory */ @@ -54,9 +52,9 @@ _nc_home_terminfo(void) if (use_terminfo_vars()) { if (MyBuffer == 0) { - if ((home = getenv("HOME")) != 0 - && my_length <= PATH_MAX) { - MyBuffer = typeMalloc(char, my_length); + if ((home = getenv("HOME")) != 0) { + unsigned want = (strlen(home) + sizeof(PRIVATE_INFO)); + MyBuffer = typeMalloc(char, want); if (MyBuffer == 0) _nc_err_abort(MSG_NO_MEMORY); (void) sprintf(MyBuffer, PRIVATE_INFO, home); diff --git a/ncurses/tinfo/lib_acs.c b/ncurses/tinfo/lib_acs.c index 6a242854..3f20c43a 100644 --- a/ncurses/tinfo/lib_acs.c +++ b/ncurses/tinfo/lib_acs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -35,7 +35,7 @@ #include #include /* ena_acs, acs_chars */ -MODULE_ID("$Id: lib_acs.c,v 1.34 2007/09/29 20:37:13 tom Exp $") +MODULE_ID("$Id: lib_acs.c,v 1.35 2008/08/03 22:59:48 tom Exp $") #if BROKEN_LINKER || USE_REENTRANT #define MyBuffer _nc_prescreen.real_acs_map @@ -72,7 +72,8 @@ _nc_init_acs(void) for (j = 1; j < ACS_LEN; ++j) { real_map[j] = 0; fake_map[j] = A_ALTCHARSET | j; - SP->_screen_acs_map[j] = FALSE; + if (SP) + SP->_screen_acs_map[j] = FALSE; } } else { for (j = 1; j < ACS_LEN; ++j) { diff --git a/ncurses/tinfo/lib_setup.c b/ncurses/tinfo/lib_setup.c index dddf808f..8cfaf12c 100644 --- a/ncurses/tinfo/lib_setup.c +++ b/ncurses/tinfo/lib_setup.c @@ -53,7 +53,7 @@ #include /* lines, columns, cur_term */ -MODULE_ID("$Id: lib_setup.c,v 1.110 2008/07/12 18:40:23 tom Exp $") +MODULE_ID("$Id: lib_setup.c,v 1.111 2008/08/03 22:42:33 tom Exp $") /**************************************************************************** * @@ -394,14 +394,16 @@ do_prototype(TERMINAL * termp) char proto; char *tmp; - tmp = getenv("CC"); - CC = *tmp; - proto = *command_character; + if ((tmp = getenv("CC")) != 0) { + if ((CC = *tmp) != 0) { + proto = *command_character; - for_each_string(i, &(termp->type)) { - for (tmp = termp->type.Strings[i]; *tmp; tmp++) { - if (*tmp == proto) - *tmp = CC; + for_each_string(i, &(termp->type)) { + for (tmp = termp->type.Strings[i]; *tmp; tmp++) { + if (*tmp == proto) + *tmp = CC; + } + } } } } diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c index d11fcf80..dce6973a 100644 --- a/ncurses/tinfo/lib_tparm.c +++ b/ncurses/tinfo/lib_tparm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -43,7 +43,7 @@ #include #include -MODULE_ID("$Id: lib_tparm.c,v 1.74 2007/09/29 20:37:13 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.75 2008/08/03 22:37:22 tom Exp $") /* * char * @@ -504,8 +504,12 @@ tparam_internal(const char *string, va_list ap) TPS(stack_ptr) = 0; if (popcount == 0) { popcount = number; - for (i = number - 1; i >= 0; i--) - npush(param[i]); + for (i = number - 1; i >= 0; i--) { + if (p_is_s[i]) + spush(p_is_s[i]); + else + npush(param[i]); + } } #ifdef TRACE if (USE_TRACEF(TRACE_CALLS)) { diff --git a/ncurses/tinfo/lib_ttyflags.c b/ncurses/tinfo/lib_ttyflags.c index 0435bc9f..a2b38a33 100644 --- a/ncurses/tinfo/lib_ttyflags.c +++ b/ncurses/tinfo/lib_ttyflags.c @@ -38,7 +38,7 @@ #include #include /* cur_term */ -MODULE_ID("$Id: lib_ttyflags.c,v 1.17 2008/06/21 20:53:06 tom Exp $") +MODULE_ID("$Id: lib_ttyflags.c,v 1.18 2008/08/03 22:10:44 tom Exp $") NCURSES_EXPORT(int) _nc_get_tty_mode(TTY * buf) @@ -65,7 +65,8 @@ _nc_get_tty_mode(TTY * buf) memset(buf, 0, sizeof(*buf)); TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s", - cur_term->Filedes, _nc_trace_ttymode(buf))); + cur_term ? cur_term->Filedes : -1, + _nc_trace_ttymode(buf))); } return (result); } @@ -93,7 +94,8 @@ _nc_set_tty_mode(TTY * buf) } } TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s", - cur_term->Filedes, _nc_trace_ttymode(buf))); + cur_term ? cur_term->Filedes : -1, + _nc_trace_ttymode(buf))); } return (result); } diff --git a/ncurses/tinfo/make_keys.c b/ncurses/tinfo/make_keys.c index 00367185..c084f87f 100644 --- a/ncurses/tinfo/make_keys.c +++ b/ncurses/tinfo/make_keys.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ /* @@ -39,7 +39,7 @@ #define USE_TERMLIB 1 #include -MODULE_ID("$Id: make_keys.c,v 1.13 2007/01/07 00:00:14 tom Exp $") +MODULE_ID("$Id: make_keys.c,v 1.14 2008/08/03 21:57:22 tom Exp $") #include @@ -71,14 +71,20 @@ static void make_keys(FILE *ifp, FILE *ofp) { char buffer[BUFSIZ]; - char from[BUFSIZ]; - char to[BUFSIZ]; + char from[256]; + char to[256]; int maxlen = 16; + int scanned; while (fgets(buffer, sizeof(buffer), ifp) != 0) { if (*buffer == '#') continue; - if (sscanf(buffer, "%s %s", to, from) == 2) { + + to[sizeof(to) - 1] = '\0'; + from[sizeof(from) - 1] = '\0'; + + scanned = sscanf(buffer, "%255s %255s", to, from); + if (scanned == 2) { int code = lookup(from); if (code == UNKNOWN) continue; diff --git a/ncurses/tinfo/name_match.c b/ncurses/tinfo/name_match.c index c8d728fa..d576901f 100644 --- a/ncurses/tinfo/name_match.c +++ b/ncurses/tinfo/name_match.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999-2005,2007 Free Software Foundation, Inc. * + * Copyright (c) 1999-2007,2008 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 * @@ -27,14 +27,14 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1999 * + * Author: Thomas E. Dickey 1999-on * ****************************************************************************/ #include #include #include -MODULE_ID("$Id: name_match.c,v 1.16 2007/04/21 21:28:13 tom Exp $") +MODULE_ID("$Id: name_match.c,v 1.17 2008/08/03 19:49:33 tom Exp $") /* * _nc_first_name(char *names) @@ -53,18 +53,21 @@ _nc_first_name(const char *const sp) if (sp == 0) { if (FirstName != 0) FreeAndNull(FirstName); - return 0; - } + } else #endif + { + if (FirstName == 0) + FirstName = typeMalloc(char, MAX_NAME_SIZE + 1); - if (FirstName == 0) - FirstName = typeMalloc(char, MAX_NAME_SIZE + 1); - for (n = 0; n < MAX_NAME_SIZE; n++) { - if ((FirstName[n] = sp[n]) == '\0' - || (FirstName[n] == '|')) - break; + if (FirstName != 0) { + for (n = 0; n < MAX_NAME_SIZE; n++) { + if ((FirstName[n] = sp[n]) == '\0' + || (FirstName[n] == '|')) + break; + } + FirstName[n] = '\0'; + } } - FirstName[n] = '\0'; return (FirstName); } diff --git a/ncurses/tinfo/parse_entry.c b/ncurses/tinfo/parse_entry.c index 375ce8ff..45f9c64c 100644 --- a/ncurses/tinfo/parse_entry.c +++ b/ncurses/tinfo/parse_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -48,7 +48,7 @@ #include #include -MODULE_ID("$Id: parse_entry.c,v 1.65 2007/08/11 16:19:02 tom Exp $") +MODULE_ID("$Id: parse_entry.c,v 1.67 2008/08/03 20:10:45 tom Exp $") #ifdef LINT static short const parametrized[] = @@ -245,6 +245,9 @@ _nc_parse_entry(struct entry *entryp, int literal, bool silent) entryp->tterm.str_table = entryp->tterm.term_names = _nc_save_str(ptr); + if (entryp->tterm.str_table == 0) + return (ERR); + DEBUG(1, ("Starting '%s'", ptr)); /* @@ -372,26 +375,28 @@ _nc_parse_entry(struct entry *entryp, int literal, bool silent) * type, this will do the job. */ - /* tell max_attributes from arrow_key_map */ if (token_type == NUMBER && !strcmp("ma", _nc_curr_token.tk_name)) { + /* tell max_attributes from arrow_key_map */ entry_ptr = _nc_find_type_entry("ma", NUMBER, _nc_get_table(_nc_syntax != 0)); + assert(entry_ptr != 0); - /* map terminfo's string MT to MT */ } else if (token_type == STRING && !strcmp("MT", _nc_curr_token.tk_name)) { + /* map terminfo's string MT to MT */ entry_ptr = _nc_find_type_entry("MT", STRING, _nc_get_table(_nc_syntax != 0)); + assert(entry_ptr != 0); - /* treat strings without following "=" as empty strings */ } else if (token_type == BOOLEAN && entry_ptr->nte_type == STRING) { + /* treat strings without following "=" as empty strings */ token_type = STRING; - /* we couldn't recover; skip this token */ } else { + /* we couldn't recover; skip this token */ if (!silent) { const char *type_name; switch (entry_ptr->nte_type) { @@ -785,11 +790,12 @@ postprocess_termcap(TERMTYPE *tp, bool has_base) base = cp + 1) { size_t len = cp - base; - for (ap = ko_xlate; ap->from; ap++) + for (ap = ko_xlate; ap->from; ap++) { if (len == strlen(ap->from) && strncmp(ap->from, base, len) == 0) break; - if (!ap->to) { + } + if (!(ap->from && ap->to)) { _nc_warning("unknown capability `%.*s' in ko string", (int) len, base); continue; diff --git a/ncurses/tinfo/read_entry.c b/ncurses/tinfo/read_entry.c index 532e5a35..b4ea61ca 100644 --- a/ncurses/tinfo/read_entry.c +++ b/ncurses/tinfo/read_entry.c @@ -42,7 +42,7 @@ #include #include -MODULE_ID("$Id: read_entry.c,v 1.101 2008/07/12 20:23:13 tom Exp $") +MODULE_ID("$Id: read_entry.c,v 1.102 2008/08/03 19:33:04 tom Exp $") #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) @@ -313,6 +313,8 @@ _nc_read_termtype(TERMTYPE *ptr, char *buffer, int limit) } if (need) { + if (ext_str_count >= (MAX_ENTRY_SIZE * 2)) + return (TGETENT_NO); if ((ptr->ext_Names = TYPE_CALLOC(char *, need)) == 0) return (TGETENT_NO); TR(TRACE_DATABASE, diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index 12172dee..b53bb210 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -54,7 +54,7 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.71 2008/07/05 20:06:25 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.72 2008/08/03 19:24:00 tom Exp $") static int total_written; @@ -275,6 +275,9 @@ _nc_write_entry(TERMTYPE *const tp) char *first_name, *other_names; char *ptr; + assert(strlen(tp->term_names) != 0); + assert(strlen(tp->term_names) < sizeof(name_list)); + (void) strcpy(name_list, tp->term_names); DEBUG(7, ("Name list = '%s'", name_list)); @@ -354,7 +357,7 @@ _nc_write_entry(TERMTYPE *const tp) start_time = 0; } - if (strlen(first_name) > sizeof(filename) - 3) + if (strlen(first_name) >= sizeof(filename) - 3) _nc_warning("terminal name too long."); sprintf(filename, LEAF_FMT "/%s", first_name[0], first_name); @@ -382,6 +385,7 @@ _nc_write_entry(TERMTYPE *const tp) } while (*other_names != '\0') { ptr = other_names++; + assert(ptr < buffer + sizeof(buffer) - 1); while (*other_names != '|' && *other_names != '\0') other_names++; @@ -691,9 +695,17 @@ write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) if (even_boundary(nextfree)) return (ERR); - nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets); + nextfree = compute_offsets(tp->Strings + STRCOUNT, + tp->ext_Strings, + offsets); TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree)); - nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings); + + if (tp->ext_Strings >= SIZEOF(offsets)) + return (ERR); + + nextfree += compute_offsets(tp->ext_Names, + extcnt, + offsets + tp->ext_Strings); TRACE_OUT(("after extended capnames, nextfree=%d", nextfree)); strmax = tp->ext_Strings + extcnt; diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c index 00a570e8..da4e5dce 100644 --- a/ncurses/trace/lib_trace.c +++ b/ncurses/trace/lib_trace.c @@ -46,7 +46,7 @@ #include -MODULE_ID("$Id: lib_trace.c,v 1.67 2008/06/07 20:49:56 tom Exp $") +MODULE_ID("$Id: lib_trace.c,v 1.68 2008/08/03 22:22:57 tom Exp $") NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */ @@ -95,10 +95,13 @@ trace(const unsigned int tracelevel) const char *mode = _nc_globals.init_trace ? "ab" : "wb"; if (TracePath[0] == '\0') { - if (getcwd(TracePath, sizeof(TracePath) - 12) == 0) { + int size = sizeof(TracePath) - 12; + if (getcwd(TracePath, size) == 0) { perror("curses: Can't get working directory"); exit(EXIT_FAILURE); } + TracePath[size] = '\0'; + assert(strlen(TracePath) <= size); strcat(TracePath, "/trace"); if (_nc_is_dir_path(TracePath)) { strcat(TracePath, ".log"); diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c index 566e7545..45a03cea 100644 --- a/ncurses/trace/lib_traceatr.c +++ b/ncurses/trace/lib_traceatr.c @@ -39,7 +39,7 @@ #include #include /* acs_chars */ -MODULE_ID("$Id: lib_traceatr.c,v 1.60 2008/05/31 16:53:15 tom Exp $") +MODULE_ID("$Id: lib_traceatr.c,v 1.63 2008/08/03 16:24:53 tom Exp $") #define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name)) @@ -75,8 +75,6 @@ color_of(int c) NCURSES_EXPORT(char *) _traceattr2(int bufnum, chtype newmode) { - char *buf = _nc_trace_buf(bufnum, BUFSIZ); - char temp[80]; static const struct { unsigned int val; const char *name; @@ -117,47 +115,54 @@ _traceattr2(int bufnum, chtype newmode) #endif /* !USE_TERMLIB */ ; size_t n; - unsigned save_nc_tracing = _nc_tracing; - _nc_tracing = 0; + char temp[80]; + char *result = _nc_trace_buf(bufnum, BUFSIZ); + + if (result != 0) { + unsigned save_nc_tracing = _nc_tracing; - strcpy(buf, l_brace); + _nc_tracing = 0; - for (n = 0; n < SIZEOF(names); n++) { - if ((newmode & names[n].val) != 0) { - if (buf[1] != '\0') - buf = _nc_trace_bufcat(bufnum, "|"); - buf = _nc_trace_bufcat(bufnum, names[n].name); + strcpy(result, l_brace); - if (names[n].val == A_COLOR) { - short pairnum = PAIR_NUMBER(newmode); + for (n = 0; n < SIZEOF(names); n++) { + if ((newmode & names[n].val) != 0) { + if (result[1] != '\0') + result = _nc_trace_bufcat(bufnum, "|"); + result = _nc_trace_bufcat(bufnum, names[n].name); + + if (names[n].val == A_COLOR) { + short pairnum = PAIR_NUMBER(newmode); #ifdef USE_TERMLIB - /* pair_content lives in libncurses */ - (void) sprintf(temp, "{%d}", pairnum); -#else - short fg, bg; - - if (pair_content(pairnum, &fg, &bg) == OK) { - (void) sprintf(temp, - "{%d = {%s, %s}}", - pairnum, - COLOR_OF(fg), - COLOR_OF(bg)); - } else { + /* pair_content lives in libncurses */ (void) sprintf(temp, "{%d}", pairnum); - } +#else + short fg, bg; + + if (pair_content(pairnum, &fg, &bg) == OK) { + (void) sprintf(temp, + "{%d = {%s, %s}}", + pairnum, + COLOR_OF(fg), + COLOR_OF(bg)); + } else { + (void) sprintf(temp, "{%d}", pairnum); + } #endif - buf = _nc_trace_bufcat(bufnum, temp); + result = _nc_trace_bufcat(bufnum, temp); + } } } - } - if (ChAttrOf(newmode) == A_NORMAL) { - if (buf[1] != '\0') - (void) _nc_trace_bufcat(bufnum, "|"); - (void) _nc_trace_bufcat(bufnum, "A_NORMAL"); - } + if (ChAttrOf(newmode) == A_NORMAL) { + if (result != 0 && result[1] != '\0') + (void) _nc_trace_bufcat(bufnum, "|"); + (void) _nc_trace_bufcat(bufnum, "A_NORMAL"); + } - _nc_tracing = save_nc_tracing; - return (_nc_trace_bufcat(bufnum, r_brace)); + _nc_tracing = save_nc_tracing; + result = _nc_trace_bufcat(bufnum, r_brace); + } + return result; } NCURSES_EXPORT(char *) @@ -181,50 +186,48 @@ _nc_altcharset_name(attr_t attr, chtype ch) unsigned int val; const char *name; } ALT_NAMES; + static const ALT_NAMES names[] = + { + {'l', "ACS_ULCORNER"}, /* upper left corner */ + {'m', "ACS_LLCORNER"}, /* lower left corner */ + {'k', "ACS_URCORNER"}, /* upper right corner */ + {'j', "ACS_LRCORNER"}, /* lower right corner */ + {'t', "ACS_LTEE"}, /* tee pointing right */ + {'u', "ACS_RTEE"}, /* tee pointing left */ + {'v', "ACS_BTEE"}, /* tee pointing up */ + {'w', "ACS_TTEE"}, /* tee pointing down */ + {'q', "ACS_HLINE"}, /* horizontal line */ + {'x', "ACS_VLINE"}, /* vertical line */ + {'n', "ACS_PLUS"}, /* large plus or crossover */ + {'o', "ACS_S1"}, /* scan line 1 */ + {'s', "ACS_S9"}, /* scan line 9 */ + {'`', "ACS_DIAMOND"}, /* diamond */ + {'a', "ACS_CKBOARD"}, /* checker board (stipple) */ + {'f', "ACS_DEGREE"}, /* degree symbol */ + {'g', "ACS_PLMINUS"}, /* plus/minus */ + {'~', "ACS_BULLET"}, /* bullet */ + {',', "ACS_LARROW"}, /* arrow pointing left */ + {'+', "ACS_RARROW"}, /* arrow pointing right */ + {'.', "ACS_DARROW"}, /* arrow pointing down */ + {'-', "ACS_UARROW"}, /* arrow pointing up */ + {'h', "ACS_BOARD"}, /* board of squares */ + {'i', "ACS_LANTERN"}, /* lantern symbol */ + {'0', "ACS_BLOCK"}, /* solid square block */ + {'p', "ACS_S3"}, /* scan line 3 */ + {'r', "ACS_S7"}, /* scan line 7 */ + {'y', "ACS_LEQUAL"}, /* less/equal */ + {'z', "ACS_GEQUAL"}, /* greater/equal */ + {'{', "ACS_PI"}, /* Pi */ + {'|', "ACS_NEQUAL"}, /* not equal */ + {'}', "ACS_STERLING"}, /* UK pound sign */ + {'\0', (char *) 0} + }; const char *result = 0; if ((attr & A_ALTCHARSET) && (acs_chars != 0)) { char *cp; char *found = 0; - /* *INDENT-OFF* */ - static const ALT_NAMES names[] = - { - { 'l', "ACS_ULCORNER" }, /* upper left corner */ - { 'm', "ACS_LLCORNER" }, /* lower left corner */ - { 'k', "ACS_URCORNER" }, /* upper right corner */ - { 'j', "ACS_LRCORNER" }, /* lower right corner */ - { 't', "ACS_LTEE" }, /* tee pointing right */ - { 'u', "ACS_RTEE" }, /* tee pointing left */ - { 'v', "ACS_BTEE" }, /* tee pointing up */ - { 'w', "ACS_TTEE" }, /* tee pointing down */ - { 'q', "ACS_HLINE" }, /* horizontal line */ - { 'x', "ACS_VLINE" }, /* vertical line */ - { 'n', "ACS_PLUS" }, /* large plus or crossover */ - { 'o', "ACS_S1" }, /* scan line 1 */ - { 's', "ACS_S9" }, /* scan line 9 */ - { '`', "ACS_DIAMOND" }, /* diamond */ - { 'a', "ACS_CKBOARD" }, /* checker board (stipple) */ - { 'f', "ACS_DEGREE" }, /* degree symbol */ - { 'g', "ACS_PLMINUS" }, /* plus/minus */ - { '~', "ACS_BULLET" }, /* bullet */ - { ',', "ACS_LARROW" }, /* arrow pointing left */ - { '+', "ACS_RARROW" }, /* arrow pointing right */ - { '.', "ACS_DARROW" }, /* arrow pointing down */ - { '-', "ACS_UARROW" }, /* arrow pointing up */ - { 'h', "ACS_BOARD" }, /* board of squares */ - { 'i', "ACS_LANTERN" }, /* lantern symbol */ - { '0', "ACS_BLOCK" }, /* solid square block */ - { 'p', "ACS_S3" }, /* scan line 3 */ - { 'r', "ACS_S7" }, /* scan line 7 */ - { 'y', "ACS_LEQUAL" }, /* less/equal */ - { 'z', "ACS_GEQUAL" }, /* greater/equal */ - { '{', "ACS_PI" }, /* Pi */ - { '|', "ACS_NEQUAL" }, /* not equal */ - { '}', "ACS_STERLING" }, /* UK pound sign */ - { '\0', (char *) 0 } - }; - /* *INDENT-OFF* */ const ALT_NAMES *sp; for (cp = acs_chars; cp[0] && cp[1]; cp += 2) { @@ -250,31 +253,35 @@ NCURSES_EXPORT(char *) _tracechtype2(int bufnum, chtype ch) { const char *found; + char *result = _nc_trace_buf(bufnum, BUFSIZ); - strcpy(_nc_trace_buf(bufnum, BUFSIZ), l_brace); - if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { - (void) _nc_trace_bufcat(bufnum, found); - } else - (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, (int)ChCharOf(ch))); + if (result != 0) { + strcpy(result, l_brace); + if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { + (void) _nc_trace_bufcat(bufnum, found); + } else + (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, (int) ChCharOf(ch))); - if (ChAttrOf(ch) != A_NORMAL) { - (void) _nc_trace_bufcat(bufnum, " | "); - (void) _nc_trace_bufcat(bufnum, - _traceattr2(bufnum + 20, ChAttrOf(ch))); - } + if (ChAttrOf(ch) != A_NORMAL) { + (void) _nc_trace_bufcat(bufnum, " | "); + (void) _nc_trace_bufcat(bufnum, + _traceattr2(bufnum + 20, ChAttrOf(ch))); + } - return (_nc_trace_bufcat(bufnum, r_brace)); + result = _nc_trace_bufcat(bufnum, r_brace); + } + return result; } NCURSES_EXPORT(char *) -_tracechtype (chtype ch) +_tracechtype(chtype ch) { return _tracechtype2(0, ch); } /* Trace 'chtype' return-values */ NCURSES_EXPORT(chtype) -_nc_retrace_chtype (chtype code) +_nc_retrace_chtype(chtype code) { T((T_RETURN("%s"), _tracechtype(code))); return code; @@ -282,63 +289,70 @@ _nc_retrace_chtype (chtype code) #if USE_WIDEC_SUPPORT NCURSES_EXPORT(char *) -_tracecchar_t2 (int bufnum, const cchar_t *ch) +_tracecchar_t2(int bufnum, const cchar_t *ch) { - char *buf = _nc_trace_buf(bufnum, BUFSIZ); + char *result = _nc_trace_buf(bufnum, BUFSIZ); attr_t attr; const char *found; - strcpy(buf, l_brace); - if (ch != 0) { - attr = AttrOfD(ch); - if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { - (void) _nc_trace_bufcat(bufnum, found); - attr &= ~A_ALTCHARSET; - } else if (isWidecExt(CHDEREF(ch))) { - (void) _nc_trace_bufcat(bufnum, "{NAC}"); - attr &= ~A_CHARTEXT; - } else { - PUTC_DATA; - int n; - - PUTC_INIT; - (void) _nc_trace_bufcat(bufnum, "{ "); - for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { - PUTC_ch = ch->chars[PUTC_i]; - if (PUTC_ch == L'\0') - break; - PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); - if (PUTC_n <= 0) { - if (PUTC_ch != L'\0') { - /* it could not be a multibyte sequence */ - (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, UChar(ch->chars[PUTC_i]))); + if (result != 0) { + strcpy(result, l_brace); + if (ch != 0) { + attr = AttrOfD(ch); + if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { + (void) _nc_trace_bufcat(bufnum, found); + attr &= ~A_ALTCHARSET; + } else if (isWidecExt(CHDEREF(ch))) { + (void) _nc_trace_bufcat(bufnum, "{NAC}"); + attr &= ~A_CHARTEXT; + } else { + PUTC_DATA; + int n; + + PUTC_INIT; + (void) _nc_trace_bufcat(bufnum, "{ "); + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + PUTC_ch = ch->chars[PUTC_i]; + if (PUTC_ch == L'\0') + break; + PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); + if (PUTC_n <= 0) { + if (PUTC_ch != L'\0') { + /* it could not be a multibyte sequence */ + (void) _nc_trace_bufcat(bufnum, + _nc_tracechar(SP, + UChar(ch->chars[PUTC_i]))); + } + break; + } + for (n = 0; n < PUTC_n; n++) { + if (n) + (void) _nc_trace_bufcat(bufnum, ", "); + (void) _nc_trace_bufcat(bufnum, + _nc_tracechar(SP, + UChar(PUTC_buf[n]))); } - break; - } - for (n = 0; n < PUTC_n; n++) { - if (n) - (void) _nc_trace_bufcat(bufnum, ", "); - (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, UChar(PUTC_buf[n]))); } + (void) _nc_trace_bufcat(bufnum, " }"); + } + if (attr != A_NORMAL) { + (void) _nc_trace_bufcat(bufnum, " | "); + (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } - (void) _nc_trace_bufcat(bufnum, " }"); - } - if (attr != A_NORMAL) { - (void) _nc_trace_bufcat(bufnum, " | "); - (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } - } - return (_nc_trace_bufcat(bufnum, r_brace)); + result = _nc_trace_bufcat(bufnum, r_brace); + } + return result; } NCURSES_EXPORT(char *) -_tracecchar_t (const cchar_t *ch) +_tracecchar_t(const cchar_t *ch) { return _tracecchar_t2(0, ch); } #endif #else -empty_module(_nc_lib_traceatr) +EMPTY_MODULE(_nc_lib_traceatr) #endif /* TRACE */ diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c index de2394c3..cc441b39 100644 --- a/ncurses/trace/lib_tracebits.c +++ b/ncurses/trace/lib_tracebits.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -35,7 +35,7 @@ #include #include /* cur_term */ -MODULE_ID("$Id: lib_tracebits.c,v 1.15 2007/06/30 16:14:20 tom Exp $") +MODULE_ID("$Id: lib_tracebits.c,v 1.17 2008/08/03 16:09:26 tom Exp $") #if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -165,58 +165,52 @@ _nc_trace_ttymode(TTY * tty) 8 + sizeof(cflags) + 8 + sizeof(lflags) + 8); + if (buf != 0) { - if (tty->c_iflag & ALLIN) - lookup_bits(buf, iflags, "iflags", tty->c_iflag); + if (tty->c_iflag & ALLIN) + lookup_bits(buf, iflags, "iflags", tty->c_iflag); - if (tty->c_oflag & ALLOUT) - lookup_bits(buf, oflags, "oflags", tty->c_oflag); + if (tty->c_oflag & ALLOUT) + lookup_bits(buf, oflags, "oflags", tty->c_oflag); - if (tty->c_cflag & ALLCTRL) - lookup_bits(buf, cflags, "cflags", tty->c_cflag); + if (tty->c_cflag & ALLCTRL) + lookup_bits(buf, cflags, "cflags", tty->c_cflag); #if defined(CS5) && defined(CS8) - { - static struct { - const char *name; - int value; - } csizes[] = { - { - "CS5 ", CS5 - }, + { + static struct { + int value; + const char *name; + } csizes[] = { +#define CS_DATA(name) { name, #name " " } + CS_DATA(CS5), #ifdef CS6 - { - "CS6 ", CS6 - }, + CS_DATA(CS6), #endif #ifdef CS7 - { - "CS7 ", CS7 - }, + CS_DATA(CS7), #endif - { - "CS8 ", CS8 - }, - }; - const char *result = "CSIZE? "; - int value = (tty->c_cflag & CSIZE); - unsigned n; + CS_DATA(CS8), + }; + const char *result = "CSIZE? "; + int value = (tty->c_cflag & CSIZE); + unsigned n; - if (value != 0) { - for (n = 0; n < SIZEOF(csizes); n++) { - if (csizes[n].value == value) { - result = csizes[n].name; - break; + if (value != 0) { + for (n = 0; n < SIZEOF(csizes); n++) { + if (csizes[n].value == value) { + result = csizes[n].name; + break; + } } } + strcat(buf, result); } - strcat(buf, result); - } #endif - if (tty->c_lflag & ALLLOCAL) - lookup_bits(buf, lflags, "lflags", tty->c_lflag); - + if (tty->c_lflag & ALLLOCAL) + lookup_bits(buf, lflags, "lflags", tty->c_lflag); + } #else /* reference: ttcompat(4M) on SunOS 4.1 */ #ifndef EVENP @@ -253,9 +247,10 @@ _nc_trace_ttymode(TTY * tty) buf = _nc_trace_buf(0, 8 + sizeof(cflags)); - - if (tty->sg_flags & ALLCTRL) { - lookup_bits(buf, cflags, "cflags", tty->sg_flags); + if (buf != 0) { + if (tty->sg_flags & ALLCTRL) { + lookup_bits(buf, cflags, "cflags", tty->sg_flags); + } } #endif return (buf); @@ -267,5 +262,5 @@ _nc_tracebits(void) return _nc_trace_ttymode(&(cur_term->Nttyb)); } #else -empty_module(_nc_tracebits) +EMPTY_MODULE(_nc_tracebits) #endif /* TRACE */ diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c index 990f11ce..79cf03b4 100644 --- a/ncurses/trace/lib_tracechr.c +++ b/ncurses/trace/lib_tracechr.c @@ -39,7 +39,7 @@ #include -MODULE_ID("$Id: lib_tracechr.c,v 1.18 2008/06/28 15:52:05 tom Exp $") +MODULE_ID("$Id: lib_tracechr.c,v 1.19 2008/08/03 15:39:29 tom Exp $") #ifdef TRACE @@ -78,5 +78,5 @@ _tracechar(int ch) return _nc_tracechar(SP, ch); } #else -empty_module(_nc_lib_tracechr) +EMPTY_MODULE(_nc_lib_tracechr) #endif diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c index d56d1a5d..6fd795c3 100644 --- a/ncurses/trace/lib_tracedmp.c +++ b/ncurses/trace/lib_tracedmp.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -39,7 +39,7 @@ #include #include -MODULE_ID("$Id: lib_tracedmp.c,v 1.29 2007/06/30 23:01:19 tom Exp $") +MODULE_ID("$Id: lib_tracedmp.c,v 1.30 2008/08/03 15:44:31 tom Exp $") #ifdef TRACE @@ -180,5 +180,5 @@ _tracedump(const char *name, WINDOW *win) } #else -empty_module(_nc_lib_tracedmp) +EMPTY_MODULE(_nc_lib_tracedmp) #endif /* TRACE */ diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c index 3b060894..74cc177d 100644 --- a/ncurses/trace/lib_tracemse.c +++ b/ncurses/trace/lib_tracemse.c @@ -38,7 +38,7 @@ #include -MODULE_ID("$Id: lib_tracemse.c,v 1.14 2008/05/31 17:20:25 tom Exp $") +MODULE_ID("$Id: lib_tracemse.c,v 1.15 2008/08/03 15:39:29 tom Exp $") #ifdef TRACE @@ -121,5 +121,5 @@ _tracemouse(MEVENT const *ep) } #else /* !TRACE */ -empty_module(_nc_lib_tracemouse) +EMPTY_MODULE(_nc_lib_tracemouse) #endif diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c index 7bf91c67..6345acc0 100644 --- a/ncurses/trace/trace_buf.c +++ b/ncurses/trace/trace_buf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -27,7 +27,7 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1997 * + * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ /* * trace_buf.c - Tracing/Debugging buffers (attributes) @@ -35,7 +35,7 @@ #include -MODULE_ID("$Id: trace_buf.c,v 1.13 2007/04/21 22:50:08 tom Exp $") +MODULE_ID("$Id: trace_buf.c,v 1.14 2008/08/03 15:13:56 tom Exp $") #define MyList _nc_globals.tracebuf_ptr #define MySize _nc_globals.tracebuf_used @@ -48,29 +48,35 @@ _nc_trace_alloc(int bufnum, size_t want) if (bufnum >= 0) { if ((size_t) (bufnum + 1) > MySize) { size_t need = (bufnum + 1) * 2; - if ((MyList = typeRealloc(TRACEBUF, need, MyList)) == 0) - return (0); - while (need > MySize) - MyList[MySize++].text = 0; + if ((MyList = typeRealloc(TRACEBUF, need, MyList)) != 0) { + while (need > MySize) + MyList[MySize++].text = 0; + } } - if (MyList[bufnum].text == 0 - || want > MyList[bufnum].size) { - MyList[bufnum].text = typeRealloc(char, want, MyList[bufnum].text); - if (MyList[bufnum].text != 0) - MyList[bufnum].size = want; + if (MyList != 0) { + if (MyList[bufnum].text == 0 + || want > MyList[bufnum].size) { + MyList[bufnum].text = typeRealloc(char, want, MyList[bufnum].text); + if (MyList[bufnum].text != 0) + MyList[bufnum].size = want; + } + result = MyList[bufnum].text; } - - result = MyList[bufnum].text; } #if NO_LEAKS else { if (MySize) { - while (MySize--) { - if (MyList[MySize].text != 0) - free(MyList[MySize].text); + if (MyList) { + while (MySize--) { + if (MyList[MySize].text != 0) { + free(MyList[MySize].text); + } + } + free(MyList); + MyList = 0; } - free(MyList); + MySize = 0; } } #endif @@ -96,10 +102,13 @@ NCURSES_EXPORT(char *) _nc_trace_bufcat(int bufnum, const char *value) { char *buffer = _nc_trace_alloc(bufnum, 0); - size_t have = strlen(buffer); + if (buffer != 0) { + size_t have = strlen(buffer); - buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value)); - (void) strcpy(buffer + have, value); + buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value)); + if (buffer != 0) + (void) strcpy(buffer + have, value); + } return buffer; } diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c index 0aa0b227..f813aba1 100644 --- a/ncurses/trace/trace_tries.c +++ b/ncurses/trace/trace_tries.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1999-2007,2008 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 * @@ -35,7 +35,7 @@ #include -MODULE_ID("$Id: trace_tries.c,v 1.12 2007/04/21 21:55:41 tom Exp $") +MODULE_ID("$Id: trace_tries.c,v 1.13 2008/08/03 15:43:30 tom Exp $") #ifdef TRACE #define my_buffer _nc_globals.tracetry_buf @@ -74,5 +74,5 @@ _nc_trace_tries(TRIES * tree) } #else -empty_module(_nc_trace_tries) +EMPTY_MODULE(_nc_trace_tries) #endif diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c index 5e63d21a..f4ee4671 100644 --- a/ncurses/trace/varargs.c +++ b/ncurses/trace/varargs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2001-2003,2007 Free Software Foundation, Inc. * + * Copyright (c) 2001-2007,2008 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 @@ #include -MODULE_ID("$Id: varargs.c,v 1.6 2007/07/14 15:51:27 tom Exp $") +MODULE_ID("$Id: varargs.c,v 1.7 2008/08/03 15:42:49 tom Exp $") #ifdef TRACE @@ -180,5 +180,5 @@ _nc_varargs(const char *fmt, va_list ap) return (MyBuffer); } #else -empty_module(_nc_varargs) +EMPTY_MODULE(_nc_varargs) #endif diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c index ed3d5bb4..bf9fb147 100644 --- a/ncurses/trace/visbuf.c +++ b/ncurses/trace/visbuf.c @@ -42,10 +42,10 @@ #include #include -MODULE_ID("$Id: visbuf.c,v 1.27 2008/07/05 23:19:59 tom Exp $") +MODULE_ID("$Id: visbuf.c,v 1.32 2008/08/04 23:07:39 tom Exp $") -#define NormalLen(len) (unsigned) ((len + 1) * 4) -#define WideLen(len) (unsigned) ((len + 1) * 4 * MB_CUR_MAX) +#define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4) +#define WideLen(len) (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX) #ifdef TRACE static const char d_quote[] = StringOf(D_QUOTE); @@ -58,9 +58,9 @@ _nc_vischar(char *tp, unsigned c) { if (c == '"' || c == '\\') { *tp++ = '\\'; - *tp++ = c; + *tp++ = (char) c; } else if (is7bits(c) && (isgraph(c) || c == ' ')) { - *tp++ = c; + *tp++ = (char) c; } else if (c == '\n') { *tp++ = '\\'; *tp++ = 'n'; @@ -80,7 +80,7 @@ _nc_vischar(char *tp, unsigned c) } else if (is7bits(c) && iscntrl(UChar(c))) { *tp++ = '\\'; *tp++ = '^'; - *tp++ = '@' + c; + *tp++ = (char) ('@' + c); } else { sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c)); tp += strlen(tp); @@ -92,7 +92,7 @@ _nc_vischar(char *tp, unsigned c) static const char * _nc_visbuf2n(int bufnum, const char *buf, int len) { - char *vbuf; + const char *vbuf; char *tp; int c; @@ -102,23 +102,27 @@ _nc_visbuf2n(int bufnum, const char *buf, int len) return ("(cancelled)"); if (len < 0) - len = strlen(buf); + len = (int) strlen(buf); #ifdef TRACE - tp = vbuf = _nc_trace_buf(bufnum, NormalLen(len)); + vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len)); #else { static char *mybuf[4]; mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]); - tp = vbuf = mybuf[bufnum]; + vbuf = tp = mybuf[bufnum]; } #endif - *tp++ = D_QUOTE; - while ((--len >= 0) && (c = *buf++) != '\0') { - tp = _nc_vischar(tp, UChar(c)); + if (tp != 0) { + *tp++ = D_QUOTE; + while ((--len >= 0) && (c = *buf++) != '\0') { + tp = _nc_vischar(tp, UChar(c)); + } + *tp++ = D_QUOTE; + *tp++ = '\0'; + } else { + vbuf = ("(_nc_visbuf2n failed)"); } - *tp++ = D_QUOTE; - *tp++ = '\0'; return (vbuf); } @@ -159,7 +163,7 @@ _nc_wchstrlen(const cchar_t *s) static const char * _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) { - char *vbuf; + const char *vbuf; char *tp; wchar_t c; @@ -167,31 +171,35 @@ _nc_viswbuf2n(int bufnum, const wchar_t *buf, int len) return ("(null)"); if (len < 0) - len = wcslen(buf); + len = (int) wcslen(buf); #ifdef TRACE - tp = vbuf = _nc_trace_buf(bufnum, WideLen(len)); + vbuf = tp = _nc_trace_buf(bufnum, WideLen(len)); #else { static char *mybuf[2]; mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]); - tp = vbuf = mybuf[bufnum]; + vbuf = tp = mybuf[bufnum]; } #endif - *tp++ = D_QUOTE; - while ((--len >= 0) && (c = *buf++) != '\0') { - char temp[CCHARW_MAX + 80]; - int j = wctomb(temp, c), k; - if (j <= 0) { - sprintf(temp, "\\u%08X", (unsigned) c); - j = strlen(temp); - } - for (k = 0; k < j; ++k) { - tp = _nc_vischar(tp, UChar(temp[k])); + if (tp != 0) { + *tp++ = D_QUOTE; + while ((--len >= 0) && (c = *buf++) != '\0') { + char temp[CCHARW_MAX + 80]; + int j = wctomb(temp, c), k; + if (j <= 0) { + sprintf(temp, "\\u%08X", (unsigned) c); + j = (int) strlen(temp); + } + for (k = 0; k < j; ++k) { + tp = _nc_vischar(tp, UChar(temp[k])); + } } + *tp++ = D_QUOTE; + *tp++ = '\0'; + } else { + vbuf = ("(_nc_viswbuf2n failed)"); } - *tp++ = D_QUOTE; - *tp++ = '\0'; return (vbuf); } @@ -244,71 +252,73 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len) int first; const char *found; + if (result != 0) { #if USE_WIDEC_SUPPORT - if (len < 0) - len = _nc_wchstrlen(buf); + if (len < 0) + len = _nc_wchstrlen(buf); #endif /* USE_WIDEC_SUPPORT */ - /* - * Display one or more strings followed by attributes. - */ - first = 0; - while (first < len) { - attr_t attr = AttrOf(buf[first]); - int last = len - 1; - int j; - - for (j = first + 1; j < len; ++j) { - if (!SameAttrOf(buf[j], buf[first])) { - last = j - 1; - break; + /* + * Display one or more strings followed by attributes. + */ + first = 0; + while (first < len) { + attr_t attr = AttrOf(buf[first]); + int last = len - 1; + int j; + + for (j = first + 1; j < len; ++j) { + if (!SameAttrOf(buf[j], buf[first])) { + last = j - 1; + break; + } } - } - result = _nc_trace_bufcat(bufnum, l_brace); - result = _nc_trace_bufcat(bufnum, d_quote); - for (j = first; j <= last; ++j) { - found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j])); - if (found != 0) { - result = _nc_trace_bufcat(bufnum, found); - attr &= ~A_ALTCHARSET; - } else + result = _nc_trace_bufcat(bufnum, l_brace); + result = _nc_trace_bufcat(bufnum, d_quote); + for (j = first; j <= last; ++j) { + found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j])); + if (found != 0) { + result = _nc_trace_bufcat(bufnum, found); + attr &= ~A_ALTCHARSET; + } else #if USE_WIDEC_SUPPORT - if (!isWidecExt(buf[j])) { - PUTC_DATA; - - PUTC_INIT; - for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { - int k; - - PUTC_ch = buf[j].chars[PUTC_i]; - if (PUTC_ch == L'\0') - break; - PUTC_n = wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st); - if (PUTC_n <= 0) - break; - for (k = 0; k < PUTC_n; k++) { - char temp[80]; - _nc_vischar(temp, UChar(PUTC_buf[k])); - result = _nc_trace_bufcat(bufnum, temp); + if (!isWidecExt(buf[j])) { + PUTC_DATA; + + PUTC_INIT; + for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { + int k; + + PUTC_ch = buf[j].chars[PUTC_i]; + if (PUTC_ch == L'\0') + break; + PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st); + if (PUTC_n <= 0) + break; + for (k = 0; k < PUTC_n; k++) { + char temp[80]; + _nc_vischar(temp, UChar(PUTC_buf[k])); + result = _nc_trace_bufcat(bufnum, temp); + } } } - } #else - { - char temp[80]; - _nc_vischar(temp, UChar(buf[j])); - result = _nc_trace_bufcat(bufnum, temp); - } + { + char temp[80]; + _nc_vischar(temp, UChar(buf[j])); + result = _nc_trace_bufcat(bufnum, temp); + } #endif /* USE_WIDEC_SUPPORT */ + } + result = _nc_trace_bufcat(bufnum, d_quote); + if (attr != A_NORMAL) { + result = _nc_trace_bufcat(bufnum, " | "); + result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); + } + result = _nc_trace_bufcat(bufnum, r_brace); + first = last + 1; } - result = _nc_trace_bufcat(bufnum, d_quote); - if (attr != A_NORMAL) { - result = _nc_trace_bufcat(bufnum, " | "); - result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); - } - result = _nc_trace_bufcat(bufnum, r_brace); - first = last + 1; } return result; } diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c index 7d8979a4..2c40997f 100644 --- a/ncurses/tty/hardscroll.c +++ b/ncurses/tty/hardscroll.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * + * and: Alexander V Lukyanov 1997-1998 * ****************************************************************************/ /****************************************************************************** @@ -145,7 +147,7 @@ AUTHOR #include -MODULE_ID("$Id: hardscroll.c,v 1.41 2007/09/29 21:48:36 tom Exp $") +MODULE_ID("$Id: hardscroll.c,v 1.42 2008/08/03 23:49:30 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -270,13 +272,14 @@ _nc_linedump(void) char *buf = 0; size_t want = (screen_lines + 1) * 4; - buf = typeMalloc(char, want); + if ((buf = typeMalloc(char, want)) != 0) { - (void) strcpy(buf, "virt"); - for (n = 0; n < screen_lines; n++) - (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(n)); - TR(TRACE_UPDATE | TRACE_MOVE, (buf)); - free(buf); + (void) strcpy(buf, "virt"); + for (n = 0; n < screen_lines; n++) + (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(n)); + TR(TRACE_UPDATE | TRACE_MOVE, (buf)); + free(buf); + } } #endif /* defined(TRACE) || defined(SCROLLDEBUG) */ diff --git a/panel/p_new.c b/panel/p_new.c index 3e48e369..27193168 100644 --- a/panel/p_new.c +++ b/panel/p_new.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000,2005 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2008 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1995 * * and: Eric S. Raymond * + * and: Juergen Pfeifer 1997-1999 * + * and: Thomas E. Dickey 2000-on * ****************************************************************************/ /* p_new.c @@ -36,7 +38,7 @@ */ #include "panel.priv.h" -MODULE_ID("$Id: p_new.c,v 1.8 2005/02/19 16:41:03 tom Exp $") +MODULE_ID("$Id: p_new.c,v 1.10 2008/08/04 18:25:48 tom Exp $") #ifdef TRACE static char *stdscr_id; @@ -54,6 +56,9 @@ root_panel(void) { assert(stdscr && !_nc_bottom_panel && !_nc_top_panel); +#if NO_LEAKS + _nc_panelhook()->destroy = del_panel; +#endif _nc_stdscr_pseudo_panel = (PANEL *) malloc(sizeof(PANEL)); if (_nc_stdscr_pseudo_panel != 0) { diff --git a/progs/dump_entry.c b/progs/dump_entry.c index 83231f3a..bd242200 100644 --- a/progs/dump_entry.c +++ b/progs/dump_entry.c @@ -29,7 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * - * and: Thomas E. Dickey 1996 on * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ #define __INTERNAL_CAPS_VISIBLE @@ -39,12 +39,14 @@ #include "termsort.c" /* this C file is generated */ #include /* so is this */ -MODULE_ID("$Id: dump_entry.c,v 1.83 2008/07/12 21:06:33 tom Exp $") +MODULE_ID("$Id: dump_entry.c,v 1.88 2008/08/04 12:36:12 tom Exp $") #define INDENT 8 #define DISCARD(string) string = ABSENT_STRING #define PRINTF (void) printf +#define OkIndex(index,array) ((int)(index) >= 0 && (int)(index) < (int) SIZEOF(array)) + typedef struct { char *text; size_t used; @@ -140,6 +142,11 @@ _nc_leaks_dump_entry(void) } #endif +#define NameTrans(check,result) \ + if (OkIndex(np->nte_index, check) \ + && check[np->nte_index]) \ + return (result[np->nte_index]) + NCURSES_CONST char * nametrans(const char *name) /* translate a capability name from termcap to terminfo */ @@ -149,18 +156,15 @@ nametrans(const char *name) if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0) switch (np->nte_type) { case BOOLEAN: - if (bool_from_termcap[np->nte_index]) - return (boolcodes[np->nte_index]); + NameTrans(bool_from_termcap, boolcodes); break; case NUMBER: - if (num_from_termcap[np->nte_index]) - return (numcodes[np->nte_index]); + NameTrans(num_from_termcap, numcodes); break; case STRING: - if (str_from_termcap[np->nte_index]) - return (strcodes[np->nte_index]); + NameTrans(str_from_termcap, strcodes); break; } @@ -352,7 +356,7 @@ version_filter(PredType type, PredIdx idx) } break; -#define is_termcap(type) (idx < (int) sizeof(type##_from_termcap) && \ +#define is_termcap(type) (OkIndex(idx, type##_from_termcap) && \ type##_from_termcap[idx]) case V_BSD: /* BSD */ @@ -389,22 +393,22 @@ force_wrap(void) static void wrap_concat(const char *src) { - int need = strlen(src); - int want = strlen(separator) + need; + unsigned need = strlen(src); + unsigned want = strlen(separator) + need; if (column > INDENT - && column + want > width) { + && column + (int) want > width) { force_wrap(); } strcpy_DYN(&outbuf, src); strcpy_DYN(&outbuf, separator); - column += need; + column += (int) need; } #define IGNORE_SEP_TRAIL(first,last,sep_trail) \ if ((size_t)(last - first) > sizeof(sep_trail)-1 \ && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \ - first += sizeof(sep_trail)-2 + first += sizeof(sep_trail)-2 /* Returns the nominal length of the buffer assuming it is termcap format, * i.e., the continuation sequence is treated as a single character ":". @@ -448,7 +452,7 @@ static bool has_params(const char *src) { bool result = FALSE; - int len = strlen(src); + int len = (int) strlen(src); int n; bool ifthen = FALSE; bool params = FALSE; @@ -553,6 +557,7 @@ fmt_complex(char *src, int level) } #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap) +#define EXTRA_CAP 20 int fmt_entry(TERMTYPE *tterm, @@ -563,7 +568,7 @@ fmt_entry(TERMTYPE *tterm, int numbers) { PredIdx i, j; - char buffer[MAX_TERMINFO_LENGTH]; + char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP]; char *capability; NCURSES_CONST char *name; int predval, len; @@ -589,13 +594,14 @@ fmt_entry(TERMTYPE *tterm, } else { strcpy_DYN(&outbuf, tterm->term_names); strcpy_DYN(&outbuf, separator); - column = outbuf.used; + column = (int) outbuf.used; force_wrap(); } for_each_boolean(j, tterm) { i = BoolIndirect(j); name = ExtBoolname(tterm, i, bool_names); + assert(strlen(name) < sizeof(buffer) - EXTRA_CAP); if (!version_filter(BOOLEAN, i)) continue; @@ -619,6 +625,7 @@ fmt_entry(TERMTYPE *tterm, for_each_number(j, tterm) { i = NumIndirect(j); name = ExtNumname(tterm, i, num_names); + assert(strlen(name) < sizeof(buffer) - EXTRA_CAP); if (!version_filter(NUMBER, i)) continue; @@ -641,9 +648,9 @@ fmt_entry(TERMTYPE *tterm, if (column != INDENT) force_wrap(); - len += num_bools - + num_values * 2 - + strlen(tterm->term_names) + 1; + len += (int) (num_bools + + num_values * 2 + + strlen(tterm->term_names) + 1); if (len & 1) len++; @@ -664,6 +671,8 @@ fmt_entry(TERMTYPE *tterm, for_each_string(j, tterm) { i = StrIndirect(j); name = ExtStrname(tterm, i, str_names); + assert(strlen(name) < sizeof(buffer) - EXTRA_CAP); + capability = tterm->Strings[i]; if (!version_filter(STRING, i)) @@ -762,7 +771,7 @@ fmt_entry(TERMTYPE *tterm, } else { sprintf(buffer, "%s=%s", name, cv); } - len += strlen(capability) + 1; + len += (int) strlen(capability) + 1; WRAP_CONCAT; } else { char *src = _nc_tic_expand(capability, @@ -778,7 +787,7 @@ fmt_entry(TERMTYPE *tterm, } else { strcpy_DYN(&tmpbuf, src); } - len += strlen(capability) + 1; + len += (int) strlen(capability) + 1; wrap_concat(tmpbuf.text); outcount = TRUE; } @@ -787,7 +796,7 @@ fmt_entry(TERMTYPE *tterm, if (capability != tterm->Strings[i]) free(capability); } - len += num_strings * 2; + len += (int) (num_strings * 2); /* * This piece of code should be an effective inverse of the functions @@ -920,7 +929,7 @@ kill_labels(TERMTYPE *tterm, int target) sprintf(name, "lf%d", n); if ((cap = find_string(tterm, name)) != ABSENT_STRING && kill_string(tterm, cap)) { - target -= (strlen(cap) + 5); + target -= (int) (strlen(cap) + 5); ++result; if (target < 0) break; @@ -945,7 +954,7 @@ kill_fkeys(TERMTYPE *tterm, int target) sprintf(name, "kf%d", n); if ((cap = find_string(tterm, name)) != ABSENT_STRING && kill_string(tterm, cap)) { - target -= (strlen(cap) + 5); + target -= (int) (strlen(cap) + 5); ++result; if (target < 0) break; @@ -1145,7 +1154,7 @@ show_entry(void) trim_trailing(); (void) fputs(outbuf.text, stdout); putchar('\n'); - return outbuf.used; + return (int) outbuf.used; } void @@ -1244,15 +1253,15 @@ repair_acsc(TERMTYPE *tp) for (n = 0; acs_chars[n] != 0; n++) { source = UChar(acs_chars[n]); if ((target = (unsigned char) acs_chars[n + 1]) != 0) { - mapped[source] = target; + mapped[source] = (char) target; n++; } else { - extra = source; + extra = (char) source; } } for (n = m = 0; n < sizeof(mapped); n++) { if (mapped[n]) { - acs_chars[m++] = n; + acs_chars[m++] = (char) n; acs_chars[m++] = mapped[n]; } } diff --git a/progs/infocmp.c b/progs/infocmp.c index 8680df35..a34153ed 100644 --- a/progs/infocmp.c +++ b/progs/infocmp.c @@ -42,7 +42,7 @@ #include -MODULE_ID("$Id: infocmp.c,v 1.96 2008/01/19 21:08:07 tom Exp $") +MODULE_ID("$Id: infocmp.c,v 1.102 2008/08/04 13:05:18 tom Exp $") #define L_CURL "{" #define R_CURL "}" @@ -568,37 +568,41 @@ same_param(const char *table, const char *param, unsigned length) static char * lookup_params(const assoc * table, char *dst, char *src) { + char *result = 0; const char *ep = strtok(src, ";"); - const assoc *ap; - do { - bool found = FALSE; + if (ep != 0) { + const assoc *ap; - for (ap = table; ap->from; ap++) { - size_t tlen = strlen(ap->from); + do { + bool found = FALSE; - if (same_param(ap->from, ep, tlen)) { - (void) strcat(dst, ap->to); - found = TRUE; - break; + for (ap = table; ap->from; ap++) { + size_t tlen = strlen(ap->from); + + if (same_param(ap->from, ep, tlen)) { + (void) strcat(dst, ap->to); + found = TRUE; + break; + } } - } - if (!found) - (void) strcat(dst, ep); - (void) strcat(dst, ";"); - } while - ((ep = strtok((char *) 0, ";"))); + if (!found) + (void) strcat(dst, ep); + (void) strcat(dst, ";"); + } while + ((ep = strtok((char *) 0, ";"))); - dst[strlen(dst) - 1] = '\0'; + dst[strlen(dst) - 1] = '\0'; - return dst; + result = dst; + } + return result; } static void analyze_string(const char *name, const char *cap, TERMTYPE *tp) { - char buf[MAX_TERMINFO_LENGTH]; char buf2[MAX_TERMINFO_LENGTH]; const char *sp; const assoc *ap; @@ -608,7 +612,6 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) return; (void) printf("%s: ", name); - buf[0] = '\0'; for (sp = cap; *sp; sp++) { int i; int csi; @@ -656,7 +659,7 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) if (!expansion) { csi = skip_csi(sp); for (ap = std_caps; ap->from; ap++) { - size_t adj = csi ? 2 : 0; + size_t adj = (size_t)(csi ? 2 : 0); len = strlen(ap->from); if (csi && skip_csi(ap->from) != csi) @@ -665,7 +668,7 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) && strncmp(ap->from + adj, sp + csi, len - adj) == 0) { expansion = ap->to; len -= adj; - len += csi; + len += (size_t) csi; break; } } @@ -675,13 +678,14 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) if (!expansion && (csi = skip_csi(sp)) != 0 && (len = strspn(sp + csi, "0123456789;")) - && (next = csi + len) + && (len < sizeof(buf3)) + && (next = (size_t) csi + len) && ((sp[next] == 'h') || (sp[next] == 'l'))) { (void) strcpy(buf2, (sp[next] == 'h') ? "ECMA+" : "ECMA-"); (void) strncpy(buf3, sp + csi, len); buf3[len] = '\0'; - len += csi + 1; + len += (size_t) csi + 1; expansion = lookup_params(std_modes, buf2, buf3); } @@ -691,13 +695,14 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) && (csi = skip_csi(sp)) != 0 && sp[csi] == '?' && (len = strspn(sp + csi + 1, "0123456789;")) - && (next = csi + 1 + len) + && (len < sizeof(buf3)) + && (next = (size_t) csi + 1 + len) && ((sp[next] == 'h') || (sp[next] == 'l'))) { (void) strcpy(buf2, (sp[next] == 'h') ? "DEC+" : "DEC-"); (void) strncpy(buf3, sp + csi + 1, len); buf3[len] = '\0'; - len += csi + 2; + len += (size_t) csi + 2; expansion = lookup_params(private_modes, buf2, buf3); } @@ -706,13 +711,14 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) if (!expansion && (csi = skip_csi(sp)) != 0 && (len = strspn(sp + csi, "0123456789;")) != 0 - && (next = csi + len) + && (len < sizeof(buf3)) + && (next = (size_t) csi + len) && sp[next] == 'm') { (void) strcpy(buf2, "SGR:"); (void) strncpy(buf3, sp + csi, len); buf3[len] = '\0'; - len += csi + 1; + len += (size_t) csi + 1; expansion = lookup_params(ecma_highlights, buf2, buf3); } @@ -720,7 +726,7 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) if (!expansion && (csi = skip_csi(sp)) != 0 && sp[csi] == 'm') { - len = csi + 1; + len = (size_t) csi + 1; (void) strcpy(buf2, "SGR:"); strcat(buf2, ecma_highlights[0].to); expansion = buf2; @@ -738,7 +744,7 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) if (strncmp(buf2, sp + csi, len) == 0) expansion = "RSR"; } - len += csi; + len += (size_t) csi; } /* now check for home-down */ @@ -755,22 +761,21 @@ analyze_string(const char *name, const char *cap, TERMTYPE *tp) expansion = "LL"; } } - len += csi; + len += (size_t) csi; } /* now look at the expansion we got, if any */ if (expansion) { - (void) sprintf(buf + strlen(buf), "{%s}", expansion); + printf("{%s}", expansion); sp += len - 1; - continue; } else { /* couldn't match anything */ buf2[0] = *sp; buf2[1] = '\0'; - (void) strcat(buf, TIC_EXPAND(buf2)); + fputs(TIC_EXPAND(buf2), stdout); } } - (void) printf("%s\n", buf); + putchar('\n'); } /*************************************************************************** @@ -789,6 +794,7 @@ file_comparison(int argc, char *argv[]) ENTRY *qp, *rp; int i, n; + memset(heads, 0, sizeof(heads)); dump_init((char *) 0, F_LITERAL, S_TERMINFO, 0, itrace, FALSE); for (n = 0; n < argc && n < MAXCOMPARE; n++) { @@ -1059,7 +1065,6 @@ static void dump_initializers(TERMTYPE *term) { unsigned n; - int size; const char *str = 0; printf("\nstatic char %s[] = \"%s\";\n\n", @@ -1138,10 +1143,6 @@ dump_initializers(TERMTYPE *term) } (void) printf("%s;\n", R_CURL); - size = (sizeof(TERMTYPE) - + (NUM_BOOLEANS(term) * sizeof(term->Booleans[0])) - + (NUM_NUMBERS(term) * sizeof(term->Numbers[0]))); - (void) printf("static char * %s[] = %s\n", name_initializer("string"), L_CURL); for_each_string(n, term) { @@ -1283,8 +1284,8 @@ main(int argc, char *argv[]) _nc_progname = _nc_rootname(argv[0]); /* make sure we have enough space to add two terminal entries */ - myargv = typeCalloc(char *, argc + 3); - memcpy(myargv, argv, sizeof(char *) * argc); + myargv = typeCalloc(char *, (size_t)(argc + 3)); + memcpy(myargv, argv, (sizeof(char *) * (size_t) argc)); argv = myargv; while ((c = getopt(argc, diff --git a/progs/progs.priv.h b/progs/progs.priv.h index d445c336..f0ea4608 100644 --- a/progs/progs.priv.h +++ b/progs/progs.priv.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -30,7 +30,7 @@ * Author: Thomas E. Dickey 1997-on * ****************************************************************************/ /* - * $Id: progs.priv.h,v 1.33 2007/10/13 20:33:53 tom Exp $ + * $Id: progs.priv.h,v 1.34 2008/08/03 17:43:05 tom Exp $ * * progs.priv.h * @@ -90,6 +90,7 @@ # endif #endif +#include #include #if DECL_ERRNO diff --git a/progs/tic.c b/progs/tic.c index 84781026..31045a63 100644 --- a/progs/tic.c +++ b/progs/tic.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -29,7 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * - * and: Thomas E. Dickey 1996 on * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ /* @@ -44,7 +44,7 @@ #include #include -MODULE_ID("$Id: tic.c,v 1.133 2007/07/21 17:45:59 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.135 2008/08/04 12:43:40 tom Exp $") const char *_nc_progname = "tic"; @@ -85,9 +85,25 @@ x\ ] \ source-file\n"; +#if NO_LEAKS +static void +free_namelist(char **src) +{ + if (src != 0) { + int n; + for (n = 0; src[n] != 0; ++n) + free(src[n]); + free(src); + } +} +#endif + static void -cleanup(void) +cleanup(char **namelst) { +#if NO_LEAKS + free_namelist(namelst); +#endif if (tmp_fp != 0) fclose(tmp_fp); if (to_remove != 0) { @@ -103,7 +119,7 @@ static void failed(const char *msg) { perror(msg); - cleanup(); + cleanup((char **) 0); ExitProgram(EXIT_FAILURE); } @@ -178,7 +194,7 @@ write_it(ENTRY * ep) d = result; t = s; while ((ch = *t++) != 0) { - *d++ = ch; + *d++ = (char) ch; if (ch == '\\') { *d++ = *t++; } else if ((ch == '%') @@ -192,7 +208,7 @@ write_it(ENTRY * ep) && value < 127 && isprint((int) value)) { *d++ = S_QUOTE; - *d++ = (int) value; + *d++ = (char) value; *d++ = S_QUOTE; t = (v + 1); } @@ -280,7 +296,7 @@ put_translate(int c) putchar(c); in_name = FALSE; } else if (c != '>') { - namebuf[used++] = c; + namebuf[used++] = (char) c; } else { /* ah! candidate name! */ char *up; NCURSES_CONST char *tp; @@ -353,19 +369,6 @@ open_input(const char *filename) return fp; } -#if NO_LEAKS -static void -free_namelist(char **src) -{ - if (src != 0) { - int n; - for (n = 0; src[n] != 0; ++n) - free(src[n]); - free(src); - } -} -#endif - /* Parse the "-e" option-value into a list of names */ static char ** make_namelist(char *src) @@ -558,7 +561,8 @@ main(int argc, char *argv[]) break; case 'V': puts(curses_version()); - return EXIT_SUCCESS; + cleanup(namelst); + ExitProgram(EXIT_SUCCESS); case 'c': check_only = TRUE; break; @@ -628,7 +632,7 @@ main(int argc, char *argv[]) if (namelst && (!infodump && !capdump)) { (void) fprintf(stderr, "Sorry, -e can't be used without -I or -C\n"); - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } #endif /* HAVE_BIG_CORE */ @@ -671,7 +675,7 @@ main(int argc, char *argv[]) _nc_progname, _nc_progname, usage_string); - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } } @@ -705,7 +709,7 @@ main(int argc, char *argv[]) /* do use resolution */ if (check_only || (!infodump && !capdump) || forceresolve) { if (!_nc_resolve_uses2(TRUE, literal) && !check_only) { - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } } @@ -799,10 +803,7 @@ main(int argc, char *argv[]) else fprintf(log_fp, "No entries written\n"); } -#if NO_LEAKS - free_namelist(namelst); -#endif - cleanup(); + cleanup(namelst); ExitProgram(EXIT_SUCCESS); } @@ -835,15 +836,19 @@ check_acs(TERMTYPE *tp) } mapped[UChar(p[0])] = p[1]; } + if (mapped[UChar('I')] && !mapped[UChar('i')]) { _nc_warning("acsc refers to 'I', which is probably an error"); } + for (p = boxes, q = missing; *p != '\0'; ++p) { if (!mapped[UChar(p[0])]) { *q++ = p[0]; } - *q = '\0'; } + *q = '\0'; + + assert(strlen(missing) <= strlen(boxes)); if (*missing != '\0' && strcmp(missing, boxes)) { _nc_warning("acsc is missing some line-drawing mapping: %s", missing); } @@ -887,10 +892,10 @@ check_colors(TERMTYPE *tp) } } -static int +static char keypad_final(const char *string) { - int result = '\0'; + char result = '\0'; if (VALID_STRING(string) && *string++ == '\033' @@ -918,6 +923,7 @@ keypad_index(const char *string) return result; } +#define MAX_KP 5 /* * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad * is mapped inconsistently. @@ -932,8 +938,8 @@ check_keypad(TERMTYPE *tp) VALID_STRING(key_b2) && VALID_STRING(key_c1) && VALID_STRING(key_c3)) { - char final[6]; - int list[5]; + char final[MAX_KP + 1]; + int list[MAX_KP]; int increase = 0; int j, k, kk; int last; @@ -947,6 +953,7 @@ check_keypad(TERMTYPE *tp) final[5] = '\0'; /* special case: legacy coding using 1,2,3,0,. on the bottom */ + assert(strlen(final) <= MAX_KP); if (!strcmp(final, "qsrpn")) return; @@ -957,22 +964,22 @@ check_keypad(TERMTYPE *tp) list[4] = keypad_index(key_c3); /* check that they're all vt100 keys */ - for (j = 0; j < 5; ++j) { + for (j = 0; j < MAX_KP; ++j) { if (list[j] < 0) { return; } } /* check if they're all in increasing order */ - for (j = 1; j < 5; ++j) { + for (j = 1; j < MAX_KP; ++j) { if (list[j] > list[j - 1]) { ++increase; } } - if (increase != 4) { + if (increase != (MAX_KP - 1)) { show[0] = '\0'; - for (j = 0, last = -1; j < 5; ++j) { + for (j = 0, last = -1; j < MAX_KP; ++j) { for (k = 0, kk = -1, test = 100; k < 5; ++k) { if (list[k] > last && list[k] < test) { @@ -981,6 +988,7 @@ check_keypad(TERMTYPE *tp) } } last = test; + assert(strlen(show) < (MAX_KP * 4)); switch (kk) { case 0: strcat(show, " ka1"); diff --git a/progs/toe.c b/progs/toe.c index 38b85cb3..855fb295 100644 --- a/progs/toe.c +++ b/progs/toe.c @@ -44,7 +44,7 @@ #include #endif -MODULE_ID("$Id: toe.c,v 1.48 2008/01/05 20:41:26 tom Exp $") +MODULE_ID("$Id: toe.c,v 1.50 2008/08/03 17:12:05 tom Exp $") #define isDotname(name) (!strcmp(name, ".") || !strcmp(name, "..")) @@ -163,6 +163,7 @@ typelist(int eargc, char *eargv[], for (i = 0; i < eargc; i++) { #if USE_DATABASE if (_nc_is_dir_path(eargv[i])) { + char *cwd_buf = 0; DIR *termdir; DIRENT *subdir; @@ -177,20 +178,30 @@ typelist(int eargc, char *eargv[], while ((subdir = readdir(termdir)) != 0) { size_t len = NAMLEN(subdir); - char buf[PATH_MAX]; + size_t cwd_len = len + strlen(eargv[i]) + 3; char name_1[PATH_MAX]; DIR *entrydir; DIRENT *entry; + cwd_buf = typeRealloc(char, cwd_len, cwd_buf); + if (cwd_buf == 0) { + perror("realloc cwd_buf"); + continue; + } + strncpy(name_1, subdir->d_name, len)[len] = '\0'; if (isDotname(name_1)) continue; - (void) sprintf(buf, "%s/%s/", eargv[i], name_1); - if (chdir(buf) != 0) + (void) sprintf(cwd_buf, "%s/%.*s/", eargv[i], (int) len, name_1); + if (chdir(cwd_buf) != 0) continue; entrydir = opendir("."); + if (entrydir == 0) { + perror(cwd_buf); + continue; + } while ((entry = readdir(entrydir)) != 0) { char name_2[PATH_MAX]; TERMTYPE lterm; @@ -222,6 +233,8 @@ typelist(int eargc, char *eargv[], closedir(entrydir); } closedir(termdir); + if (cwd_buf != 0) + free(cwd_buf); } #if USE_HASHED_DB else { diff --git a/progs/tset.c b/progs/tset.c index 3d609122..1c1480a2 100644 --- a/progs/tset.c +++ b/progs/tset.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -104,7 +104,7 @@ char *ttyname(int fd); #include #include -MODULE_ID("$Id: tset.c,v 1.70 2007/10/13 22:22:04 tom Exp $") +MODULE_ID("$Id: tset.c,v 1.73 2008/08/04 12:47:05 tom Exp $") extern char **environ; @@ -168,7 +168,7 @@ failed(const char *msg) char temp[BUFSIZ]; unsigned len = strlen(_nc_progname) + 2; - if (len < sizeof(temp) - 12) { + if ((int) len < (int) sizeof(temp) - 12) { strcpy(temp, _nc_progname); strcat(temp, ": "); } else { @@ -440,11 +440,15 @@ add_mapping(const char *port, char *arg) mapp->conditional = ~mapp->conditional & (EQ | GT | LT); /* If user specified a port with an option flag, set it. */ - done:if (port) { - if (mapp->porttype) - badmopt:err("illegal -m option format: %s", copy); + done: + if (port) { + if (mapp->porttype) { + badmopt: + err("illegal -m option format: %s", copy); + } mapp->porttype = port; } + free(copy); #ifdef MAPDEBUG (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY"); (void) printf("type: %s\n", mapp->type); @@ -780,16 +784,16 @@ reset_mode(void) #ifdef NLDLY | NLDLY #endif -#ifdef CRDLY +#ifdef CRDLY | CRDLY #endif -#ifdef TABDLY +#ifdef TABDLY | TABDLY #endif -#ifdef BSDLY +#ifdef BSDLY | BSDLY #endif -#ifdef VTDLY +#ifdef VTDLY | VTDLY #endif #ifdef FFDLY @@ -1128,9 +1132,9 @@ usage(void) static char arg_to_char(void) { - return (optarg[0] == '^' && optarg[1] != '\0') - ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1])) - : optarg[0]; + return (char) ((optarg[0] == '^' && optarg[1] != '\0') + ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1])) + : optarg[0]); } int @@ -1218,9 +1222,9 @@ main(int argc, char **argv) can_restore = TRUE; original = oldmode = mode; #ifdef TERMIOS - ospeed = cfgetospeed(&mode); + ospeed = (NCURSES_OSPEED) cfgetospeed(&mode); #else - ospeed = mode.sg_ospeed; + ospeed = (NCURSES_OSPEED) mode.sg_ospeed; #endif if (!strcmp(_nc_progname, PROG_RESET)) { @@ -1293,7 +1297,7 @@ main(int argc, char **argv) * environmental variable SHELL ending in "csh". */ if ((var = getenv("SHELL")) != 0 - && ((len = strlen(leaf = _nc_basename(var))) >= 3) + && ((len = (int) strlen(leaf = _nc_basename(var))) >= 3) && !strcmp(leaf + len - 3, "csh")) p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n"; else diff --git a/test/blue.c b/test/blue.c index 0f15d01d..dac0c761 100644 --- a/test/blue.c +++ b/test/blue.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 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 * @@ -40,7 +40,7 @@ * results, use the ncurses(3) library. On non-Intel machines, SVr4 curses is * just as good. * - * $Id: blue.c,v 1.29 2006/05/20 15:38:18 tom Exp $ + * $Id: blue.c,v 1.30 2008/08/03 18:20:27 tom Exp $ */ #include @@ -173,6 +173,7 @@ deal_cards(void) { int ptr, card = 0, value, csuit, crank, suit, aces[4]; + memset(aces, 0, sizeof(aces)); for (suit = HEARTS; suit <= CLUBS; suit++) { ptr = freeptr[suit]; grid[ptr++] = NOCARD; /* 1st card space is blank */ diff --git a/test/bs.c b/test/bs.c index 4d32c706..f9572beb 100644 --- a/test/bs.c +++ b/test/bs.c @@ -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.46 2008/07/05 20:56:25 tom Exp $ + * $Id: bs.c,v 1.47 2008/08/03 18:30:28 tom Exp $ */ #include @@ -465,6 +465,7 @@ initgame(void) (void) clearok(stdscr, TRUE); (void) refresh(); } else if (c == 'r') { + assert(ss != 0); prompt(1, "Random-placing your %s", ss->name); randomplace(PLAYER, ss); placeship(PLAYER, ss, TRUE); @@ -480,6 +481,7 @@ initgame(void) } error((char *) NULL); } else if (strchr("hjkl8462", c)) { + assert(ss != 0); ss->x = curx; ss->y = cury; diff --git a/test/cardfile.c b/test/cardfile.c index a0034728..68ae4fe0 100644 --- a/test/cardfile.c +++ b/test/cardfile.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: cardfile.c,v 1.33 2008/04/12 22:05:53 tom Exp $ + * $Id: cardfile.c,v 1.35 2008/08/05 00:42:24 tom Exp $ * * File format: text beginning in column 1 is a title; other text is content. */ @@ -133,12 +133,13 @@ add_content(CARD * card, const char *content) content = skip(content); if ((total = strlen(content)) != 0) { - if ((offset = strlen(card->content)) != 0) { + if (card->content != 0 && (offset = strlen(card->content)) != 0) { total += 1 + offset; card->content = typeRealloc(char, total + 1, card->content); if (card->content) strcpy(card->content + offset++, " "); } else { + offset = 0; if (card->content != 0) free(card->content); card->content = typeMalloc(char, total + 1); diff --git a/test/demo_defkey.c b/test/demo_defkey.c index e49ac298..195ef544 100644 --- a/test/demo_defkey.c +++ b/test/demo_defkey.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_defkey.c,v 1.18 2008/04/12 22:06:12 tom Exp $ + * $Id: demo_defkey.c,v 1.19 2008/08/04 16:24:47 tom Exp $ * * Demonstrate the define_key() function. * Thomas Dickey - 2002/11/23 @@ -76,6 +76,7 @@ visichar(int ch) static char temp[10]; ch = UChar(ch); + assert(ch >= 0 && ch < 256); if (ch == '\\') { strcpy(temp, "\\\\"); } else if (ch == '\033') { diff --git a/test/demo_forms.c b/test/demo_forms.c index a4b0724f..e3691a6b 100644 --- a/test/demo_forms.c +++ b/test/demo_forms.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2003-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 2003-2007,2008 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 * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_forms.c,v 1.24 2007/07/21 17:45:09 tom Exp $ + * $Id: demo_forms.c,v 1.25 2008/08/04 15:45:04 tom Exp $ * * Demonstrate a variety of functions from the form library. * Thomas Dickey - 2003/4/26 @@ -316,7 +316,7 @@ demo_forms(void) { WINDOW *w; FORM *form; - FIELD *f[100]; + FIELD *f[100]; // FIXME memset to zero int finished = 0, c; unsigned n = 0; int pg; @@ -334,6 +334,7 @@ demo_forms(void) refresh(); /* describe the form */ + memset(f, 0, sizeof(f)); for (pg = 0; pg < 4; ++pg) { char label[80]; sprintf(label, "Sample Form Page %d", pg + 1); @@ -398,31 +399,32 @@ demo_forms(void) f[n++] = (FIELD *) 0; - form = new_form(f); + if ((form = new_form(f)) != 0) { - display_form(form); + display_form(form); - w = form_win(form); - also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0); - show_current_field(also, form); + w = form_win(form); + also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0); + show_current_field(also, form); - while (!finished) { - switch (edit_field(form, &c)) { - case E_OK: - break; - case E_UNKNOWN_COMMAND: - finished = my_form_driver(form, c); - break; - default: - beep(); - break; + while (!finished) { + switch (edit_field(form, &c)) { + case E_OK: + break; + case E_UNKNOWN_COMMAND: + finished = my_form_driver(form, c); + break; + default: + beep(); + break; + } + show_current_field(also, form); } - show_current_field(also, form); - } - erase_form(form); + erase_form(form); - free_form(form); + free_form(form); + } for (c = 0; f[c] != 0; c++) free_field(f[c]); noraw(); diff --git a/test/demo_menus.c b/test/demo_menus.c index 34d582ed..fc7c8935 100644 --- a/test/demo_menus.c +++ b/test/demo_menus.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_menus.c,v 1.24 2008/04/12 22:03:33 tom Exp $ + * $Id: demo_menus.c,v 1.27 2008/08/04 15:37:52 tom Exp $ * * Demonstrate a variety of functions from the menu library. * Thomas Dickey - 2005/4/9 @@ -256,23 +256,35 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number) static void menu_destroy(MENU * m) { - ITEM **ip; int count; + Trace(("menu_destroy %p", m)); if (m != 0) { - delwin(menu_sub(m)); - delwin(menu_win(m)); + ITEM **items = menu_items(m); + const char *blob = 0; - ip = menu_items(m); count = item_count(m); + Trace(("menu_destroy %p count %d", m, count)); + if ((count > 0) && (m == mpSelect)) { + blob = item_name(*items); + } + unpost_menu(m); free_menu(m); -#if 0 - if (count > 0) { - while (*ip) { - Trace(("freeing item %d:%d", ip - menu_items(m), count)); - free_item(*ip++); + + /* free the extra data allocated in build_select_menu() */ + if ((count > 0) && (m == mpSelect)) { + if (blob) { + Trace(("freeing blob %p", blob)); + free((char *) blob); } + free(items); + } +#ifdef TRACE + if ((count > 0) && (m == mpTrace)) { + ITEM **ip = items; + while (*ip) + free(*ip++); } #endif } @@ -340,6 +352,7 @@ build_select_menu(MenuNo number, char *filename) ITEM **ip; CONST_MENUS char **ap = 0; + CONST_MENUS char **myList = 0; unsigned count = 0; if (filename != 0) { @@ -347,12 +360,13 @@ build_select_menu(MenuNo number, char *filename) if (stat(filename, &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFREG && sb.st_size != 0) { - unsigned size = sb.st_size; + size_t size = (size_t) sb.st_size; unsigned j, k; char *blob = typeMalloc(char, size + 1); CONST_MENUS char **list = typeCalloc(CONST_MENUS char *, size + 1); items = typeCalloc(ITEM *, size + 1); + Trace(("build_select_menu blob=%p, items=%p", blob, items)); if (blob != 0 && list != 0) { FILE *fp = fopen(filename, "r"); if (fp != 0) { @@ -374,7 +388,7 @@ build_select_menu(MenuNo number, char *filename) } list[k] = 0; count = k; - ap = list; + ap = myList = list; } fclose(fp); } @@ -393,6 +407,8 @@ build_select_menu(MenuNo number, char *filename) *ip = 0; mpSelect = menu_create(items, (int) count, 1, number); + if (myList != 0) + free(myList); } static int diff --git a/test/demo_panels.c b/test/demo_panels.c index 396d76c6..55593c03 100755 --- a/test/demo_panels.c +++ b/test/demo_panels.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_panels.c,v 1.31 2008/07/05 23:13:47 tom Exp $ + * $Id: demo_panels.c,v 1.33 2008/08/04 13:33:48 tom Exp $ * * Demonstrate a variety of functions from the panel library. */ @@ -212,9 +212,9 @@ mkpanel(short color, int rows, int cols, int tly, int tlx) if ((pan = new_panel(win)) == 0) { delwin(win); } else if (use_colors) { - short fg = ((color == COLOR_BLUE) - ? COLOR_WHITE - : COLOR_BLACK); + short fg = (short) ((color == COLOR_BLUE) + ? COLOR_WHITE + : COLOR_BLACK); short bg = color; init_pair(color, fg, bg); @@ -253,8 +253,8 @@ my_create_panel(PANEL ** pans, int which, FillPanel myFill) { PANEL *pan = 0; int code; - int pair = which; - short fg = (pair == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK; + short pair = (short) which; + short fg = (short) ((pair == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK); short bg = pair; int x0, y0, x1, y1; @@ -369,7 +369,8 @@ static void fill_panel(PANEL * pan) { WINDOW *win = panel_window(pan); - int num = ((const char *) panel_userptr(pan))[1]; + const char *userptr = (const char *) panel_userptr(pan); + int num = (userptr && *userptr) ? userptr[1] : '?'; int y, x; wmove(win, 1, 1); @@ -388,7 +389,8 @@ static void fill_unboxed(PANEL * pan) { WINDOW *win = panel_window(pan); - int num = ((const char *) panel_userptr(pan))[1]; + const char *userptr = (const char *) panel_userptr(pan); + int num = (userptr && *userptr) ? userptr[1] : '?'; int y, x; for (y = 0; y < getmaxy(win); y++) { @@ -634,7 +636,7 @@ get_command(PANEL * px[MAX_PANELS + 1], char *buffer, int limit) if (log_in != 0) { if (fgets(buffer, limit - 3, log_in) != 0) { - length = strlen(buffer); + length = (int) strlen(buffer); while (length > 0 && isspace(UChar(buffer[length - 1]))) buffer[--length] = '\0'; waddstr(win, buffer); @@ -664,22 +666,22 @@ get_command(PANEL * px[MAX_PANELS + 1], char *buffer, int limit) } else if (isdigit(UChar(c0))) { wprintw(win, " %c", ch); buffer[length++] = ' '; - buffer[length++] = c0 = ch; + buffer[length++] = (char) (c0 = ch); } else { wprintw(win, "%c", ch); - buffer[length++] = c0 = ch; + buffer[length++] = (char) (c0 = ch); } } else if (ok_digit(ch)) { if (isalpha(UChar(c0))) { wprintw(win, "%c", ch); - buffer[length++] = c0 = ch; + buffer[length++] = (char) (c0 = ch); } else { beep(); } } else if (ch == ' ') { if (isdigit(UChar(c0))) { wprintw(win, "%c", ch); - buffer[length++] = c0 = ch; + buffer[length++] = (char) (c0 = ch); } else { beep(); } @@ -715,7 +717,7 @@ demo_panels(InitPanel myInit, FillPanel myFill) memset(px, 0, sizeof(px)); while (get_command(px, buffer, sizeof(buffer))) { - int limit = strlen(buffer); + int limit = (int) strlen(buffer); for (itmp = 0; itmp < limit; itmp += 3) { do_panel(px, buffer + itmp, myFill); } diff --git a/test/ditto.c b/test/ditto.c index 9d1116c2..b8aebac9 100644 --- a/test/ditto.c +++ b/test/ditto.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey (1998-on) * - * $Id: ditto.c,v 1.30 2008/06/14 23:00:26 tom Exp $ + * $Id: ditto.c,v 1.32 2008/08/04 13:21:41 tom Exp $ * * The program illustrates how to set up multiple screens from a single * program. @@ -151,10 +151,11 @@ open_tty(char *path) int amaster; int aslave; char slave_name[1024]; - char s_option[1024]; + char s_option[sizeof(slave_name) + 80]; char *leaf; - if (openpty(&amaster, &aslave, slave_name, 0, 0) != 0) + if (openpty(&amaster, &aslave, slave_name, 0, 0) != 0 + || strlen(slave_name) > sizeof(slave_name) - 1) failed("openpty"); if ((leaf = strrchr(slave_name, '/')) == 0) { errno = EISDIR; @@ -166,6 +167,8 @@ open_tty(char *path) _exit(0); } fp = fdopen(amaster, "r+"); + if (fp == 0) + failed(path); #else struct stat sb; @@ -180,6 +183,7 @@ open_tty(char *path) failed(path); printf("opened %s\n", path); #endif + assert(fp != 0); return fp; } @@ -195,8 +199,8 @@ init_screen(SCREEN *sp GCC_UNUSED, void *arg) scrollok(stdscr, TRUE); box(stdscr, 0, 0); - target->windows = typeCalloc(WINDOW *, target->length); - target->peeks = typeCalloc(PEEK, target->length); + target->windows = typeCalloc(WINDOW *, (size_t) target->length); + target->peeks = typeCalloc(PEEK, (size_t) target->length); high = (LINES - 2) / target->length; wide = (COLS - 2); @@ -290,7 +294,7 @@ write_screen(SCREEN *sp GCC_UNUSED, void *arg GCC_UNUSED) while ((ch = peek_fifo(fifo, peek)) > 0) { changed = TRUE; - waddch(win, ch); + waddch(win, (chtype) ch); wnoutrefresh(win); } } @@ -357,7 +361,7 @@ main(int argc, char *argv[]) if (argc <= 1) usage(); - if ((data = typeCalloc(DITTO, argc)) == 0) + if ((data = typeCalloc(DITTO, (size_t) argc)) == 0) failed("calloc data"); for (j = 0; j < argc; j++) { diff --git a/test/gdc.c b/test/gdc.c index 7aa2e0ca..ef220fed 100644 --- a/test/gdc.c +++ b/test/gdc.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -33,7 +33,7 @@ * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling * - * $Id: gdc.c,v 1.29 2007/07/21 17:45:09 tom Exp $ + * $Id: gdc.c,v 1.31 2008/08/03 23:58:42 tom Exp $ */ #include @@ -85,13 +85,14 @@ drawbox(bool scrolling) mvaddch(YBASE - 1, XBASE + XLENGTH, ACS_URCORNER); mvaddch(YBASE + YDEPTH, XBASE - 1, ACS_LLCORNER); - mvinchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH); - for (n = 0; n < XLENGTH; n++) { - if (!scrolling) - bottom[n] &= ~A_COLOR; - bottom[n] = ACS_HLINE | (bottom[n] & (A_ATTRIBUTES | A_COLOR)); + if ((mvinchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH)) != ERR) { + for (n = 0; n < XLENGTH; n++) { + if (!scrolling) + bottom[n] &= ~A_COLOR; + bottom[n] = ACS_HLINE | (bottom[n] & (A_ATTRIBUTES | A_COLOR)); + } + mvaddchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH); } - mvaddchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH); mvaddch(YBASE + YDEPTH, XBASE + XLENGTH, ACS_LRCORNER); move(YBASE, XBASE - 1); @@ -186,6 +187,7 @@ main(int argc, char *argv[]) } if (optind < argc) { count = atoi(argv[optind++]); + assert(count >= 0); } if (optind < argc) usage(); diff --git a/test/hanoi.c b/test/hanoi.c index a763dce8..bd0fb10e 100644 --- a/test/hanoi.c +++ b/test/hanoi.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 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 * @@ -41,7 +41,7 @@ * * Date: 05.Nov.90 * - * $Id: hanoi.c,v 1.25 2006/04/22 22:41:22 tom Exp $ + * $Id: hanoi.c,v 1.27 2008/08/04 10:57:59 tom Exp $ */ #include @@ -81,6 +81,7 @@ static int TileColour[] = COLOR_RED, /* Length 19 */ }; static int NMoves = 0; +static bool AutoFlag = FALSE; static void InitTiles(int NTiles); static void DisplayTiles(void); @@ -95,7 +96,6 @@ int main(int argc, char **argv) { int NTiles, FromCol, ToCol; - bool AutoFlag = 0; setlocale(LC_ALL, ""); @@ -246,15 +246,18 @@ DisplayTiles(void) /* Draw tiles */ for (peg = 0; peg < NPEGS; peg++) { for (SlotNo = 0; SlotNo < Pegs[peg].Count; SlotNo++) { - memset(TileBuf, ' ', Pegs[peg].Length[SlotNo]); - TileBuf[Pegs[peg].Length[SlotNo]] = '\0'; - if (has_colors()) - attrset(COLOR_PAIR(LENTOIND(Pegs[peg].Length[SlotNo]))); - else - attrset(A_REVERSE); - mvaddstr(BASELINE - (SlotNo + 1), - (int) (PegPos[peg] - Pegs[peg].Length[SlotNo] / 2), - TileBuf); + unsigned len = Pegs[peg].Length[SlotNo]; + if (len < sizeof(TileBuf) - 1 && len < (unsigned) PegPos[peg]) { + memset(TileBuf, ' ', len); + TileBuf[len] = '\0'; + if (has_colors()) + attrset(COLOR_PAIR(LENTOIND(len))); + else + attrset(A_REVERSE); + mvaddstr(BASELINE - (SlotNo + 1), + (int) (PegPos[peg] - len / 2), + TileBuf); + } } } attrset(A_NORMAL); @@ -278,7 +281,8 @@ GetMove(int *From, int *To) return TRUE; *To -= ('0' + 1); refresh(); - napms(500); + if (!AutoFlag) + napms(500); move(STATUSLINE, 0); clrtoeol(); diff --git a/test/knight.c b/test/knight.c index af0ca8ab..f9ba1dc2 100644 --- a/test/knight.c +++ b/test/knight.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 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 * @@ -33,7 +33,7 @@ * Eric S. Raymond July 22 1995. Mouse support * added September 20th 1995. * - * $Id: knight.c,v 1.27 2006/04/22 22:41:22 tom Exp $ + * $Id: knight.c,v 1.28 2008/08/03 23:04:26 tom Exp $ */ #include @@ -383,7 +383,7 @@ drawmove(chtype tchar, int oldy, int oldx, int row, int column) mark_possibles(oldy, oldx, ' '); } - if (row != -1 && column != -1) { + if (row >= 0 && column >= 0) { markcell(trail, row, column); mark_possibles(row, column, minus); board[row][column] = TRUE; diff --git a/test/ncurses.c b/test/ncurses.c index b55031fe..05e754e9 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.315 2008/07/05 23:26:35 tom Exp $ +$Id: ncurses.c,v 1.324 2008/08/04 16:27:54 tom Exp $ ***************************************************************************/ @@ -212,7 +212,7 @@ wGetstring(WINDOW *win, char *buffer, int limit) getyx(win, y0, x0); wattrset(win, A_REVERSE); - x = strlen(buffer); + x = (int) strlen(buffer); while (!done) { if (x > (int) strlen(buffer)) x = (int) strlen(buffer); @@ -254,10 +254,10 @@ wGetstring(WINDOW *win, char *buffer, int limit) beep(); } else if ((int) strlen(buffer) < limit) { int j; - for (j = strlen(buffer) + 1; j > x; --j) { + for (j = (int) strlen(buffer) + 1; j > x; --j) { buffer[j] = buffer[j - 1]; } - buffer[x++] = ch; + buffer[x++] = (char) ch; } else { flash(); } @@ -343,7 +343,7 @@ wGet_wstring(WINDOW *win, wchar_t *buffer, int limit) getyx(win, y0, x0); wattrset(win, A_REVERSE); - x = wcslen(buffer); + x = (int) wcslen(buffer); while (!done) { if (x > (int) wcslen(buffer)) x = (int) wcslen(buffer); @@ -422,10 +422,10 @@ wGet_wstring(WINDOW *win, wchar_t *buffer, int limit) beep(); } else if ((int) wcslen(buffer) < limit) { int j; - for (j = wcslen(buffer) + 1; j > x; --j) { + for (j = (int) wcslen(buffer) + 1; j > x; --j) { buffer[j] = buffer[j - 1]; } - buffer[x++] = ch; + buffer[x++] = (wchar_t) ch; } else { beep(); } @@ -583,7 +583,7 @@ wgetch_help(WINDOW *win, bool flags[]) printw("Type any key to see its %s value. Also:\n", flags['k'] ? "keypad" : "literal"); for (n = 0; n < SIZEOF(help); ++n) { - int row = 1 + (n % chk); + int row = 1 + (int) (n % chk); int col = (n >= chk) ? COLS / 2 : 0; int flg = ((strstr(help[n], "toggle") != 0) && (flags[UChar(*help[n])] != FALSE)); @@ -635,6 +635,8 @@ remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win) { unsigned need = (level + 1) * 2; + assert(level < COLS); + if (winstack == 0) { len_winstack = 20; winstack = typeMalloc(WINSTACK, len_winstack); @@ -812,7 +814,7 @@ wgetch_test(unsigned level, WINDOW *win, int delay) #endif (void) waddstr(win, keyname(c)); } else if (c > 0x80) { - unsigned c2 = (c & 0x7f); + unsigned c2 = (unsigned) (c & 0x7f); if (isprint(c2)) (void) wprintw(win, "M-%c", UChar(c2)); else @@ -931,13 +933,14 @@ wcstos(const wchar_t *src) const wchar_t *tmp = src; memset(&state, 0, sizeof(state)); - if ((need = wcsrtombs(0, &tmp, 0, &state)) > 0) { - unsigned have = need; - result = typeCalloc(char, have + 1); - tmp = src; - if (wcsrtombs(result, &tmp, have, &state) != have) { - free(result); - result = 0; + if ((need = (int) wcsrtombs(0, &tmp, 0, &state)) > 0) { + unsigned have = (unsigned) need; + if ((result = typeCalloc(char, have + 1)) != 0) { + tmp = src; + if (wcsrtombs(result, &tmp, have, &state) != have) { + free(result); + result = 0; + } } } return result; @@ -996,7 +999,9 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) wprintw(win, "wgetn_wstr returns an error."); } else { int n; - for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ; + for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) { + ; + } if ((temp = wcstos(wchar_buf)) != 0) { wprintw(win, "I saw %d characters:\n\t`%s'.", (int) wcslen(wchar_buf), temp); @@ -1072,7 +1077,7 @@ wget_wch_test(unsigned level, WINDOW *win, int delay) if (c < 256 && iscntrl(c)) { (void) wprintw(win, "%s (control character)", unctrl(c)); } else { - wchar_t c2 = c; + wchar_t c2 = (wchar_t) c; waddnwstr(win, &c2, 1); (void) wprintw(win, " = %#x (printable character)", c); } @@ -1204,22 +1209,22 @@ cycle_color_attr(int ch, short *fg, short *bg, short *tx) if (use_colors) { switch (ch) { case 'f': - *fg = (*fg + 1); + *fg = (short) (*fg + 1); break; case 'F': - *fg = (*fg - 1); + *fg = (short) (*fg - 1); break; case 'b': - *bg = (*bg + 1); + *bg = (short) (*bg + 1); break; case 'B': - *bg = (*bg - 1); + *bg = (short) (*bg - 1); break; case 't': - *tx = (*tx + 1); + *tx = (short) (*tx + 1); break; case 'T': - *tx = (*tx - 1); + *tx = (short) (*tx - 1); break; default: beep(); @@ -1227,17 +1232,17 @@ cycle_color_attr(int ch, short *fg, short *bg, short *tx) break; } if (*fg >= COLORS) - *fg = min_colors; + *fg = (short) min_colors; if (*fg < min_colors) - *fg = COLORS - 1; + *fg = (short) (COLORS - 1); if (*bg >= COLORS) - *bg = min_colors; + *bg = (short) min_colors; if (*bg < min_colors) - *bg = COLORS - 1; + *bg = (short) (COLORS - 1); if (*tx >= COLORS) *tx = -1; if (*tx < -1) - *tx = COLORS - 1; + *tx = (short) (COLORS - 1); } else { beep(); error = TRUE; @@ -1254,11 +1259,11 @@ adjust_attr_string(int adjust) if (first >= ' ' && last <= '~') { /* 32..126 */ int j, k; for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) { - attr_test_string[j] = k; + attr_test_string[j] = (char) k; if (((k + 1 - first) % 5) == 0) { - ++j; - if (j < MAX_ATTRSTRING) - attr_test_string[j] = ' '; + if (++j >= MAX_ATTRSTRING) + break; + attr_test_string[j] = ' '; } } while (j < MAX_ATTRSTRING) @@ -1448,10 +1453,10 @@ attr_test(void) do { int row = 2; chtype normal = A_NORMAL | BLANK; - chtype extras = ac; + chtype extras = (chtype) ac; if (use_colors) { - short pair = (fg != COLOR_BLACK || bg != COLOR_BLACK); + short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK); if (pair != 0) { pair = 1; if (init_pair(pair, fg, bg) == ERR) { @@ -1514,9 +1519,9 @@ wide_adjust_attr_string(int adjust) for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) { wide_attr_test_string[j] = k; if (((k + 1 - first) % 5) == 0) { - ++j; - if (j < MAX_ATTRSTRING) - wide_attr_test_string[j] = ' '; + if (++j >= MAX_ATTRSTRING) + break; + wide_attr_test_string[j] = ' '; } } while (j < MAX_ATTRSTRING) @@ -1727,7 +1732,7 @@ wide_attr_test(void) short extras = 0; if (use_colors) { - pair = (fg != COLOR_BLACK || bg != COLOR_BLACK); + pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK); if (pair != 0) { pair = 1; if (init_pair(pair, fg, bg) == ERR) { @@ -1916,14 +1921,14 @@ color_test(void) show_color_name(top + 2, (i + 1) * width, i, opt_wide); /* show a grid of colors, with color names/ numbers on the left */ - for (i = (base_row * per_row); i < pairs_max; i++) { + for (i = (short) (base_row * per_row); i < pairs_max; i++) { int row = grid_top + (i / per_row) - base_row; int col = (i % per_row + 1) * width; short pair = i; if (row >= 0 && move(row, col) != ERR) { - short fg = i % COLORS; - short bg = i / COLORS; + short fg = (short) (i % COLORS); + short bg = (short) (i / COLORS); init_pair(pair, fg, bg); attron((attr_t) COLOR_PAIR(pair)); @@ -2100,10 +2105,10 @@ wide_color_test(void) for (i = (base_row * per_row); i < pairs_max; i++) { int row = grid_top + (i / per_row) - base_row; int col = (i % per_row + 1) * width; - int pair = i; + short pair = (short) i; if (row >= 0 && move(row, col) != ERR) { - init_pair(pair, i % COLORS, i / COLORS); + init_pair(pair, (short) (i % COLORS), (short) (i / COLORS)); color_set(pair, NULL); if (opt_acsc) attr_on((attr_t) A_ALTCHARSET, NULL); @@ -2231,13 +2236,13 @@ change_color(short current, int field, int value, int usebase) switch (field) { case 0: - red = usebase ? red + value : value; + red = (short) (usebase ? (red + value) : value); break; case 1: - green = usebase ? green + value : value; + green = (short) (usebase ? (green + value) : value); break; case 2: - blue = usebase ? blue + value : value; + blue = (short) (usebase ? (blue + value) : value); break; } @@ -2263,8 +2268,8 @@ static void color_edit(void) /* display the color test pattern, without trying to edit colors */ { - short i; - short current = 0; + int i; + int current = 0; int this_c = 0, value = 0, field = 0; int last_c; int top_color = 0; @@ -2274,7 +2279,7 @@ color_edit(void) refresh(); for (i = 0; i < max_colors; i++) - init_pair(i, COLOR_WHITE, i); + init_pair((short) i, (short) COLOR_WHITE, (short) i); mvprintw(LINES - 2, 0, "Number: %d", value); @@ -2285,7 +2290,7 @@ color_edit(void) mvaddstr(0, 20, "Color RGB Value Editing"); attroff(A_BOLD); - for (i = top_color; + for (i = (short) top_color; (i - top_color < page_size) && (i < max_colors); i++) { char numeric[80]; @@ -2299,7 +2304,7 @@ color_edit(void) addstr(" "); attrset(A_NORMAL); - color_content(i, &red, &green, &blue); + color_content((short) i, &red, &green, &blue); addstr(" R = "); if (current == i && field == 0) attron(A_STANDOUT); @@ -2386,15 +2391,15 @@ color_edit(void) break; case '+': - change_color(current, field, value, 1); + change_color((short) current, field, value, 1); break; case '-': - change_color(current, field, -value, 1); + change_color((short) current, field, -value, 1); break; case '=': - change_color(current, field, value, 0); + change_color((short) current, field, value, 0); break; case '?': @@ -2599,13 +2604,13 @@ slk_test(void) #if HAVE_SLK_COLOR case 'F': if (use_colors) { - fg = (fg + 1) % COLORS; + fg = (short) ((fg + 1) % COLORS); call_slk_color(fg, bg); } break; case 'B': if (use_colors) { - bg = (bg + 1) % COLORS; + bg = (short) ((bg + 1) % COLORS); call_slk_color(fg, bg); } break; @@ -2731,13 +2736,13 @@ wide_slk_test(void) case 'F': if (use_colors) { - fg = (fg + 1) % COLORS; + fg = (short) ((fg + 1) % COLORS); call_slk_color(fg, bg); } break; case 'B': if (use_colors) { - bg = (bg + 1) % COLORS; + bg = (short) ((bg + 1) % COLORS); call_slk_color(fg, bg); } break; @@ -2830,10 +2835,10 @@ cycle_colors(int ch, int *fg, int *bg, short *pair) break; } if (result) { - *pair = (*fg != COLOR_BLACK || *bg != COLOR_BLACK); + *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK); if (*pair != 0) { *pair = 1; - if (init_pair(*pair, *fg, *bg) == ERR) { + if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) { result = FALSE; } } @@ -2862,8 +2867,8 @@ show_upper_chars(unsigned first, int repeat, attr_t attr, short pair) for (code = first; code <= last; code++) { int count = repeat; - int row = 2 + ((code - first) % 16); - int col = ((code - first) / 16) * COLS / 2; + int row = 2 + ((int) (code - first) % 16); + int col = ((int) (code - first) / 16) * COLS / 2; char tmp[80]; sprintf(tmp, "%3u (0x%x)", code, code); mvprintw(row, col, "%*s: ", COLS / 4, tmp); @@ -2902,8 +2907,8 @@ show_pc_chars(int repeat, attr_t attr, short pair) } for (code = 0; code < 256; code++) { int count = repeat; - int row = 3 + (code / 16) + (code >= 128); - int col = 8 + (code % 16) * PC_COLS; + int row = 3 + (int) (code / 16) + (code >= 128); + int col = 8 + (int) (code % 16) * PC_COLS; if ((code % 16) == 0) mvprintw(row, 0, "0x%02x:", code); move(row, col); @@ -3101,7 +3106,7 @@ acs_display(void) if (last_show_acs != 0) last_show_acs(repeat, attr, pair); else - show_upper_chars(digit * 32 + 128, repeat, attr, pair); + show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair); mvprintw(LINES - 3, 0, "Note: ANSI terminals may not display C1 characters."); @@ -3137,7 +3142,7 @@ merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair) *dst = *src; if (count > 0) { - if ((wch = typeMalloc(wchar_t, count + 1)) != 0) { + if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) { if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) { attr |= (ignore_attr & A_ALTCHARSET); setcchar(dst, wch, attr, pair, 0); @@ -3574,6 +3579,12 @@ FRAME #define is_scrollok(win) FALSE #endif +static WINDOW * +frame_win(FRAME * curp) +{ + return (curp != 0) ? curp->wind : stdscr; +} + /* We need to know if these flags are actually set, so don't look in FRAME. * These names are known to work with SVr4 curses as well as ncurses. The * _use_keypad name does not work with Solaris 8. @@ -3581,7 +3592,7 @@ FRAME static bool HaveKeypad(FRAME * curp) { - WINDOW *win = (curp ? curp->wind : stdscr); + WINDOW *win = frame_win(curp); (void) win; return is_keypad(win); } @@ -3589,7 +3600,7 @@ HaveKeypad(FRAME * curp) static bool HaveScroll(FRAME * curp) { - WINDOW *win = (curp ? curp->wind : stdscr); + WINDOW *win = frame_win(curp); (void) win; return is_scrollok(win); } @@ -3687,7 +3698,7 @@ static void newwin_report(FRAME * curp) /* report on the cursor's current position, then restore it */ { - WINDOW *win = (curp != 0) ? curp->wind : stdscr; + WINDOW *win = frame_win(curp); int y, x; if (win != stdscr) @@ -3814,7 +3825,7 @@ getwindow(void) static void newwin_move(FRAME * curp, int dy, int dx) { - WINDOW *win = (curp != 0) ? curp->wind : stdscr; + WINDOW *win = frame_win(curp); int cur_y, cur_x; int max_y, max_x; @@ -3834,19 +3845,21 @@ newwin_move(FRAME * curp, int dy, int dx) static FRAME * delete_framed(FRAME * fp, bool showit) { - FRAME *np; + FRAME *np = 0; - fp->last->next = fp->next; - fp->next->last = fp->last; + if (fp != 0) { + fp->last->next = fp->next; + fp->next->last = fp->last; - if (showit) { - werase(fp->wind); - wrefresh(fp->wind); - } - delwin(fp->wind); + if (showit) { + werase(fp->wind); + wrefresh(fp->wind); + } + delwin(fp->wind); - np = (fp == fp->next) ? 0 : fp->next; - free(fp); + np = (fp == fp->next) ? 0 : fp->next; + free(fp); + } return np; } @@ -3872,9 +3885,13 @@ acs_and_scroll(void) transient((FRAME *) 0, (char *) 0); switch (c) { case CTRL('C'): - neww = typeCalloc(FRAME, 1); - if ((neww->wind = getwindow()) == (WINDOW *) 0) + if ((neww = typeCalloc(FRAME, 1)) == 0) { + goto breakout; + } + if ((neww->wind = getwindow()) == (WINDOW *) 0) { + free(neww); goto breakout; + } if (current == 0) { /* First element, */ neww->next = neww; /* so point it at itself */ @@ -3907,12 +3924,12 @@ acs_and_scroll(void) case CTRL('F'): /* scroll current window forward */ if (current) - wscrl(current->wind, 1); + wscrl(frame_win(current), 1); break; case CTRL('B'): /* scroll current window backwards */ if (current) - wscrl(current->wind, -1); + wscrl(frame_win(current), -1); break; case CTRL('K'): /* toggle keypad mode for current */ @@ -3931,13 +3948,13 @@ acs_and_scroll(void) #if HAVE_PUTWIN && HAVE_GETWIN case CTRL('W'): /* save and delete window */ - if (current == current->next) { + if ((current != 0) && (current == current->next)) { transient(current, "Will not save/delete ONLY window"); break; } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) { transient(current, "Can't open screen dump file"); } else { - (void) putwin(current->wind, fp); + (void) putwin(frame_win(current), fp); (void) fclose(fp); current = delete_framed(current, TRUE); @@ -3948,17 +3965,18 @@ acs_and_scroll(void) if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) { transient(current, "Can't open screen dump file"); } else { - neww = typeCalloc(FRAME, 1); + if ((neww = typeCalloc(FRAME, 1)) != 0) { - neww->next = current->next; - neww->last = current; - neww->last->next = neww; - neww->next->last = neww; + neww->next = current ? current->next : 0; + neww->last = current; + neww->last->next = neww; + neww->next->last = neww; - neww->wind = getwin(fp); - (void) fclose(fp); + neww->wind = getwin(fp); - wrefresh(neww->wind); + wrefresh(neww->wind); + } + (void) fclose(fp); } break; #endif @@ -4045,13 +4063,13 @@ acs_and_scroll(void) case KEY_DC: { int y, x; - getyx(current->wind, y, x); + getyx(frame_win(current), y, x); if (--x < 0) { if (--y < 0) break; - x = getmaxx(current->wind) - 1; + x = getmaxx(frame_win(current)) - 1; } - mvwdelch(current->wind, y, x); + mvwdelch(frame_win(current), y, x); } break; @@ -4067,7 +4085,7 @@ acs_and_scroll(void) break; } newwin_report(current); - usescr = (current ? current->wind : stdscr); + usescr = frame_win(current); wrefresh(usescr); } while (!isQuit(c = wGetchar(usescr)) @@ -4154,7 +4172,7 @@ mkpanel(short color, int rows, int cols, int tly, int tlx) if ((pan = new_panel(win)) == 0) { delwin(win); } else if (use_colors) { - short fg = (color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK; + short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK); short bg = color; init_pair(color, fg, bg); @@ -4205,7 +4223,8 @@ static void fill_panel(PANEL * pan) { WINDOW *win = panel_window(pan); - int num = ((const char *) panel_userptr(pan))[1]; + const char *userptr = (const char *) panel_userptr(pan); + int num = (userptr && *userptr) ? userptr[1] : '?'; int y, x; wmove(win, 1, 1); @@ -4241,7 +4260,8 @@ static void fill_wide_panel(PANEL * pan) { WINDOW *win = panel_window(pan); - int num = ((const char *) panel_userptr(pan))[1]; + const char *userptr = (const char *) panel_userptr(pan); + int num = (userptr && *userptr) ? userptr[1] : '?'; int y, x; wmove(win, 1, 1); @@ -4449,7 +4469,7 @@ panner_legend(int line) "Use <,> (or h,l) to grow/shrink the panner horizontally.", "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s." }; - int n = (SIZEOF(legend) - (LINES - line)); + int n = ((int) SIZEOF(legend) - (LINES - line)); if (line < LINES && (n >= 0)) { move(line, 0); if (show_panner_legend) @@ -4492,7 +4512,7 @@ fill_pad(WINDOW *panpad, bool pan_lines) waddch(panpad, pan_lines ? ACS_LTEE : '+'); else waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') + - (gridcount++ % 26))); + (int) (gridcount++ % 26))); } else if (y % GRIDSIZE == 0) waddch(panpad, pan_lines ? ACS_HLINE : '-'); else if (x % GRIDSIZE == 0) @@ -4701,8 +4721,8 @@ panner(WINDOW *pad, int length = (portx - top_x - 1); float ratio = ((float) length) / ((float) pxmax); - lowend = (int) (top_x + (basex * ratio)); - highend = (int) (top_x + ((basex + length) * ratio)); + lowend = (int) ((float) top_x + ((float) basex * ratio)); + highend = (int) ((float) top_x + ((float) (basex + length) * ratio)); do_h_line(porty - 1, top_x, ACS_HLINE, lowend); if (highend < portx) { @@ -4718,8 +4738,8 @@ panner(WINDOW *pad, int length = (porty - top_y - 1); float ratio = ((float) length) / ((float) pymax); - lowend = (int) (top_y + (basey * ratio)); - highend = (int) (top_y + ((basey + length) * ratio)); + lowend = (int) ((float) top_y + ((float) basey * ratio)); + highend = (int) ((float) top_y + ((float) (basey + length) * ratio)); do_v_line(top_y, portx - 1, ACS_VLINE, lowend); if (highend < porty) { @@ -5045,8 +5065,10 @@ menu_test(void) mvaddstr(5, 0, " Press return to exit."); refresh(); - for (ap = animals; *ap; ap++) - *ip++ = new_item(*ap, ""); + for (ap = animals; *ap; ap++) { + if ((*ip = new_item(*ap, "")) != 0) + ++ip; + } *ip = (ITEM *) 0; m = new_menu(items); @@ -5201,8 +5223,11 @@ trace_set(void) refresh(); - for (n = 0; t_tbl[n].name != 0; n++) - *ip++ = new_item(t_tbl[n].name, ""); + for (n = 0; t_tbl[n].name != 0; n++) { + if ((*ip = new_item(t_tbl[n].name, "")) != 0) { + ++ip; + } + } *ip = (ITEM *) 0; m = new_menu(items); @@ -5330,7 +5355,7 @@ edit_secure(FIELD * me, int c) len = (long) (char *) field_userptr(me); if (c <= KEY_MAX) { if (isgraph(c) && (len + 1) < (int) sizeof(temp)) { - temp[len++] = c; + temp[len++] = (char) c; temp[len] = 0; set_field_buffer(me, 1, temp); c = '*'; @@ -5533,7 +5558,7 @@ FIELDCHECK_CB(mi_field_check) /* force the form to display a leading capital */ if (islower(UChar(s[0]))) { - s[0] = toupper(UChar(s[0])); + s[0] = (char) toupper(UChar(s[0])); set_field_buffer(fld, 0, s); } return TRUE; @@ -5602,6 +5627,7 @@ demo_forms(void) refresh(); /* describe the form */ + memset(f, 0, sizeof(f)); f[n++] = make_label(0, 15, "Sample Form"); f[n++] = make_label(2, 0, "Last Name"); @@ -5625,32 +5651,33 @@ demo_forms(void) set_field_type(f[n - 1], fty_passwd); f[n++] = (FIELD *) 0; - form = new_form(f); + if ((form = new_form(f)) != 0) { - display_form(form); + display_form(form); - w = form_win(form); - raw(); - nonl(); /* lets us read ^M's */ - while (!finished) { - switch (form_driver(form, c = form_virtualize(form, w))) { - case E_OK: - mvaddstr(5, 57, field_buffer(secure, 1)); - clrtoeol(); - refresh(); - break; - case E_UNKNOWN_COMMAND: - finished = my_form_driver(form, c); - break; - default: - beep(); - break; + w = form_win(form); + raw(); + nonl(); /* lets us read ^M's */ + while (!finished) { + switch (form_driver(form, c = form_virtualize(form, w))) { + case E_OK: + mvaddstr(5, 57, field_buffer(secure, 1)); + clrtoeol(); + refresh(); + break; + case E_UNKNOWN_COMMAND: + finished = my_form_driver(form, c); + break; + default: + beep(); + break; + } } - } - erase_form(form); + erase_form(form); - free_form(form); + free_form(form); + } for (c = 0; f[c] != 0; c++) free_field(f[c]); free_fieldtype(fty_middle); @@ -5717,7 +5744,7 @@ overlap_helpitem(int state, int item, char *message) static void overlap_test_1_attr(WINDOW *win, int flavor, int col) { - short cpair = 1 + (flavor * 2) + col; + short cpair = (short) (1 + (flavor * 2) + col); switch (flavor) { case 0: @@ -5740,7 +5767,7 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col) static void overlap_test_2_attr(WINDOW *win, int flavor, int col) { - short cpair = 9 + (flavor * 2) + col; + short cpair = (short) (9 + (flavor * 2) + col); switch (flavor) { case 0: @@ -5771,6 +5798,7 @@ overlap_help(int state, int flavors[OVERLAP_FLAVORS]) if (state < 0) state += OVERLAP_FLAVORS; state = state % OVERLAP_FLAVORS; + assert(state >= 0 && state < OVERLAP_FLAVORS); for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) { row = item / 2; @@ -6282,7 +6310,7 @@ main_menu(bool top) */ command = 0; for (;;) { - char ch; + char ch = '\0'; if (read(fileno(stdin), &ch, 1) <= 0) { if (command == 0) command = 'q'; @@ -6393,7 +6421,7 @@ main(int argc, char *argv[]) #endif #ifdef TRACE case 't': - save_trace = strtol(optarg, 0, 0); + save_trace = (unsigned) strtol(optarg, 0, 0); break; #endif default: @@ -6454,7 +6482,7 @@ main(int argc, char *argv[]) if (can_change_color()) { short cp; - all_colors = typeMalloc(RGB_DATA, max_colors); + all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors); for (cp = 0; cp < max_colors; ++cp) { color_content(cp, &all_colors[cp].red, @@ -6479,9 +6507,9 @@ main(int argc, char *argv[]) && okRGB(red) && okRGB(green) && okRGB(blue)) { - all_colors[c].red = (red * 1000) / scale; - all_colors[c].green = (green * 1000) / scale; - all_colors[c].blue = (blue * 1000) / scale; + all_colors[c].red = (short) ((red * 1000) / scale); + all_colors[c].green = (short) ((green * 1000) / scale); + all_colors[c].blue = (short) ((blue * 1000) / scale); } } fclose(fp); diff --git a/test/newdemo.c b/test/newdemo.c index 84d3f82c..d43996b2 100644 --- a/test/newdemo.c +++ b/test/newdemo.c @@ -2,7 +2,7 @@ * newdemo.c - A demo program using PDCurses. The program illustrate * the use of colours for text output. * - * $Id: newdemo.c,v 1.30 2008/02/09 16:41:29 tom Exp $ + * $Id: newdemo.c,v 1.31 2008/08/03 20:19:38 tom Exp $ */ #include @@ -319,6 +319,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) j = 0; /* Draw running As across in RED */ set_colors(win, 7, COLOR_RED, COLOR_GREEN); + memset(save, ' ', sizeof(save)); for (i = 2; i < width - 4; ++i) { k = mvwinch(win, 4, i); if (k == ERR) diff --git a/test/testcurs.c b/test/testcurs.c index 2f3368c1..6a2e53ff 100644 --- a/test/testcurs.c +++ b/test/testcurs.c @@ -7,7 +7,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.38 2008/04/12 22:00:27 tom Exp $ + * $Id: testcurs.c,v 1.39 2008/08/03 17:58:09 tom Exp $ */ #include @@ -44,7 +44,7 @@ static const COMMAND command[] = {"Input Test", inputTest}, {"Output Test", outputTest} }; -#define MAX_OPTIONS SIZEOF(command) +#define MAX_OPTIONS (int) SIZEOF(command) #if !HAVE_STRDUP #define strdup my_strdup @@ -70,7 +70,7 @@ main( int old_option = (-1); int new_option = 0; bool quit = FALSE; - unsigned n; + int n; setlocale(LC_ALL, ""); @@ -120,12 +120,15 @@ main( display_menu(old_option, new_option); break; case KEY_UP: - new_option = (new_option == 0) ? new_option : new_option - 1; + new_option = ((new_option == 0) + ? new_option + : new_option - 1); display_menu(old_option, new_option); break; case KEY_DOWN: - new_option = (new_option == MAX_OPTIONS - 1) ? new_option : - new_option + 1; + new_option = ((new_option == (MAX_OPTIONS - 1)) + ? new_option + : new_option + 1); display_menu(old_option, new_option); break; case 'Q': @@ -676,37 +679,38 @@ padTest(WINDOW *dummy GCC_UNUSED) { WINDOW *pad, *spad; - pad = newpad(50, 100); - wattron(pad, A_REVERSE); - mvwaddstr(pad, 5, 2, "This is a new pad"); - wattrset(pad, A_NORMAL); - mvwaddstr(pad, 8, 0, - "The end of this line should be truncated here:except now"); - mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); - wmove(pad, 10, 1); - wclrtoeol(pad); - mvwaddstr(pad, 10, 1, " Press any key to continue"); - prefresh(pad, 0, 0, 0, 0, 10, 45); - keypad(pad, TRUE); - raw(); - wgetch(pad); + if ((pad = newpad(50, 100)) != 0) { + wattron(pad, A_REVERSE); + mvwaddstr(pad, 5, 2, "This is a new pad"); + wattrset(pad, A_NORMAL); + mvwaddstr(pad, 8, 0, + "The end of this line should be truncated here:except now"); + mvwaddstr(pad, 11, 1, "This line should not appear.It will now"); + wmove(pad, 10, 1); + wclrtoeol(pad); + mvwaddstr(pad, 10, 1, " Press any key to continue"); + prefresh(pad, 0, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); - spad = subpad(pad, 12, 25, 6, 52); - mvwaddstr(spad, 2, 2, "This is a new subpad"); - box(spad, 0, 0); - prefresh(pad, 0, 0, 0, 0, 15, 75); - keypad(pad, TRUE); - raw(); - wgetch(pad); + spad = subpad(pad, 12, 25, 6, 52); + mvwaddstr(spad, 2, 2, "This is a new subpad"); + box(spad, 0, 0); + prefresh(pad, 0, 0, 0, 0, 15, 75); + keypad(pad, TRUE); + raw(); + wgetch(pad); - mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); - mvwaddstr(pad, 40, 1, " Press any key to continue"); - prefresh(pad, 30, 0, 0, 0, 10, 45); - keypad(pad, TRUE); - raw(); - wgetch(pad); + mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad"); + mvwaddstr(pad, 40, 1, " Press any key to continue"); + prefresh(pad, 30, 0, 0, 0, 10, 45); + keypad(pad, TRUE); + raw(); + wgetch(pad); - delwin(pad); + delwin(pad); + } } static void @@ -714,13 +718,17 @@ display_menu(int old_option, int new_option) { int i; + assert((new_option >= 0) && (new_option < MAX_OPTIONS)); + attrset(A_NORMAL); mvaddstr(3, 20, "PDCurses Test Program"); for (i = 0; i < (int) MAX_OPTIONS; i++) mvaddstr(5 + i, 25, command[i].text); - if (old_option != (-1)) + + if ((old_option >= 0) && (old_option < MAX_OPTIONS)) mvaddstr(5 + old_option, 25, command[old_option].text); + attrset(A_REVERSE); mvaddstr(5 + new_option, 25, command[new_option].text); attrset(A_NORMAL); diff --git a/test/view.c b/test/view.c index 9834e444..3925b842 100644 --- a/test/view.c +++ b/test/view.c @@ -50,7 +50,7 @@ * scroll operation worked, and the refresh() code only had to do a * partial repaint. * - * $Id: view.c,v 1.67 2008/01/19 21:01:21 tom Exp $ + * $Id: view.c,v 1.68 2008/08/03 11:37:07 tom Exp $ */ #include @@ -238,7 +238,8 @@ main(int argc, char *argv[]) CATCHALL(SIG_IGN); break; case 'n': - if ((MAXLINES = atoi(optarg)) < 1) + if ((MAXLINES = atoi(optarg)) < 1 || + (MAXLINES + 2) <= 1) usage(); break; #if CAN_RESIZE @@ -508,9 +509,10 @@ show_all(const char *tag) time_t this_time; #if CAN_RESIZE - sprintf(temp, "%s (%3dx%3d) col %d ", tag, LINES, COLS, shift); + sprintf(temp, "%.20s (%3dx%3d) col %d ", tag, LINES, COLS, shift); i = strlen(temp); - sprintf(temp + i, "view %.*s", (int) (sizeof(temp) - 7 - i), fname); + if ((i + 7) < (int) sizeof(temp)) + sprintf(temp + i, "view %.*s", (int) (sizeof(temp) - 7 - i), fname); #else (void) tag; sprintf(temp, "view %.*s", (int) sizeof(temp) - 7, fname); diff --git a/test/xmas.c b/test/xmas.c index 9b66cca7..b838bae2 100644 --- a/test/xmas.c +++ b/test/xmas.c @@ -92,7 +92,7 @@ /******************************************************************************/ /* - * $Id: xmas.c,v 1.23 2008/04/12 22:05:04 tom Exp $ + * $Id: xmas.c,v 1.24 2008/08/03 11:08:59 tom Exp $ */ #include @@ -206,44 +206,48 @@ main(int argc GCC_UNUSED, char **argv GCC_UNUSED) } curs_set(0); - treescrn = newwin(16, 27, 3, 53); - treescrn2 = newwin(16, 27, 3, 53); - treescrn3 = newwin(16, 27, 3, 53); - treescrn4 = newwin(16, 27, 3, 53); - treescrn5 = newwin(16, 27, 3, 53); - treescrn6 = newwin(16, 27, 3, 53); - treescrn7 = newwin(16, 27, 3, 53); - treescrn8 = newwin(16, 27, 3, 53); - - dotdeer0 = newwin(3, 71, 0, 8); - - stardeer0 = newwin(4, 56, 0, 8); - - lildeer0 = newwin(7, 53, 0, 8); - lildeer1 = newwin(2, 4, 0, 0); - lildeer2 = newwin(2, 4, 0, 0); - lildeer3 = newwin(2, 4, 0, 0); - - middeer0 = newwin(15, 42, 0, 8); - middeer1 = newwin(3, 7, 0, 0); - middeer2 = newwin(3, 7, 0, 0); - middeer3 = newwin(3, 7, 0, 0); - - bigdeer0 = newwin(10, 23, 0, 0); - bigdeer1 = newwin(10, 23, 0, 0); - bigdeer2 = newwin(10, 23, 0, 0); - bigdeer3 = newwin(10, 23, 0, 0); - bigdeer4 = newwin(10, 23, 0, 0); - - lookdeer0 = newwin(10, 25, 0, 0); - lookdeer1 = newwin(10, 25, 0, 0); - lookdeer2 = newwin(10, 25, 0, 0); - lookdeer3 = newwin(10, 25, 0, 0); - lookdeer4 = newwin(10, 25, 0, 0); - - w_holiday = newwin(1, 26, 3, 27); - - w_del_msg = newwin(1, 19, 23, 60); + if ((treescrn = newwin(16, 27, 3, 53)) == 0 || + (treescrn2 = newwin(16, 27, 3, 53)) == 0 || + (treescrn3 = newwin(16, 27, 3, 53)) == 0 || + (treescrn4 = newwin(16, 27, 3, 53)) == 0 || + (treescrn5 = newwin(16, 27, 3, 53)) == 0 || + (treescrn6 = newwin(16, 27, 3, 53)) == 0 || + (treescrn7 = newwin(16, 27, 3, 53)) == 0 || + (treescrn8 = newwin(16, 27, 3, 53)) == 0 || + + (dotdeer0 = newwin(3, 71, 0, 8)) == 0 || + + (stardeer0 = newwin(4, 56, 0, 8)) == 0 || + + (lildeer0 = newwin(7, 53, 0, 8)) == 0 || + (lildeer1 = newwin(2, 4, 0, 0)) == 0 || + (lildeer2 = newwin(2, 4, 0, 0)) == 0 || + (lildeer3 = newwin(2, 4, 0, 0)) == 0 || + + (middeer0 = newwin(15, 42, 0, 8)) == 0 || + (middeer1 = newwin(3, 7, 0, 0)) == 0 || + (middeer2 = newwin(3, 7, 0, 0)) == 0 || + (middeer3 = newwin(3, 7, 0, 0)) == 0 || + + (bigdeer0 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer1 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer2 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer3 = newwin(10, 23, 0, 0)) == 0 || + (bigdeer4 = newwin(10, 23, 0, 0)) == 0 || + + (lookdeer0 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer1 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer2 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer3 = newwin(10, 25, 0, 0)) == 0 || + (lookdeer4 = newwin(10, 25, 0, 0)) == 0 || + + (w_holiday = newwin(1, 26, 3, 27)) == 0 || + + (w_del_msg = newwin(1, 19, 23, 60)) == 0) { + endwin(); + fprintf(stderr, "Cannot create windows - screen too small\n"); + ExitProgram(EXIT_FAILURE); + } mvwaddstr(w_del_msg, 0, 0, "Hit any key to quit"); -- 2.44.0