--- NEWS +++ NEWS 2007-04-07 18:55:45.000000000 +0200 @@ -103,6 +103,36 @@ it is not possible to add this informati + modify shared-library rules to allow FreeBSD 3.x to use rpath. + update config.guess, config.sub +20060407 + > other fixes prompted by inspection for Coverity report: + + modify ifdef's for c++ binding to use try/catch/throw statements + + add a null-pointer check in tack/ansi.c request_cfss() + + fix a memory leak in ncurses/base/wresize.c + + corrected check for valid memu/meml capabilities in + progs/dump_entry.c when handling V_HPUX case. + > fixes based on Coverity report: + + remove dead code in test/bs.c + + remove dead code in test/demo_defkey.c + + remove an unused assignment in progs/infocmp.c + + fix a limit check in tack/ansi.c tools_charset() + + fix tack/ansi.c tools_status() to perform the VT320/VT420 + tests in request_cfss(). The function had exited too soon. + + fix a memory leak in tic.c's make_namelist() + + fix a couple of places in tack/output.c which did not check for EOF. + + fix a loop-condition in test/bs.c + + add index checks in lib_color.c for color palettes + + add index checks in progs/dump_entry.c for version_filter() handling + of V_BSD case. + + fix a possible null-pointer dereference in copywin() + + fix a possible null-pointer dereference in waddchnstr() + + add a null-pointer check in _nc_expand_try() + + add a null-pointer check in tic.c's make_namelist() + + add a null-pointer check in _nc_expand_try() + + add null-pointer checks in test/cardfile.c + + fix a double-free in ncurses/tinfo/trim_sgr0.c + + fix a double-free in ncurses/base/wresize.c + + add try/catch block to c++/cursesmain.cc + 20061217 5.6 release for upload to ftp.gnu.org 20061217 --- configure +++ configure 2007-04-07 00:54:52.000000000 +0200 @@ -13892,7 +13892,7 @@ ac_link='$CXX -o conftest$ac_exeext $CXX ac_compiler_gnu=$ac_cv_cxx_compiler_gnu ac_main_return=return -for ac_header in typeinfo +for ac_header in iostream typeinfo do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` echo "$as_me:13893: checking for $ac_header" >&5 --- configure.in +++ configure.in 2007-04-07 00:53:21.000000000 +0200 @@ -1210,7 +1210,7 @@ if test -n "$CXX" ; then ;; esac - AC_CHECK_HEADERS(typeinfo) + AC_CHECK_HEADERS(iostream typeinfo) CF_BOOL_DECL CF_BOOL_SIZE --- c++/cursesmain.cc +++ c++/cursesmain.cc 2008-04-09 17:57:56.093616466 +0200 @@ -34,6 +34,13 @@ #include "internal.h" #include "cursesapp.h" +#if CPP_HAS_TRY_CATCH && HAVE_IOSTREAM +#include +#else +#undef CPP_HAS_TRY_CATCH +#define CPP_HAS_TRY_CATCH 0 +#endif + MODULE_ID("$Id: cursesmain.cc,v 1.13 2007/01/27 20:29:27 tom Exp $") #if HAVE_LOCALE_H @@ -62,8 +69,20 @@ int main(int argc, char* argv[]) A->handleArgs(argc,argv); ::endwin(); +#if CPP_HAS_TRY_CATCH + try { + res = (*A)(); + ::endwin(); + } + catch(const NCursesException &e) { + ::endwin(); + std::cerr << e.message << std::endl; + res = e.errorno; + } +#else res = (*A)(); ::endwin(); +#endif #if NO_LEAKS delete A; _nc_free_and_exit(res); --- c++/cursesp.h +++ c++/cursesp.h 2007-04-07 02:47:22.000000000 +0200 @@ -83,7 +83,7 @@ protected: return uptr->m_user; } - void OnError (int err) const THROWS((NCursesPanelException)) + void OnError (int err) const THROWS(NCursesPanelException) { if (err==ERR) THROW(new NCursesPanelException (this, err)); --- c++/etip.h.in +++ c++/etip.h.in 2007-04-07 02:49:39.000000000 +0200 @@ -330,23 +330,33 @@ public: inline void THROW(const NCursesException *e) { #if defined(__GNUG__) && defined(__EXCEPTIONS) # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8)) - (*lib_error_handler)(e?e->classname():"",e?e->message:""); + (*lib_error_handler)(e ? e->classname() : "", e ? e->message : ""); #else - throw *e; +#define CPP_HAS_TRY_CATCH 1 #endif #elif defined(__SUNPRO_CC) # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5) genericerror(1, ((e != 0) ? (char *)(e->message) : "")); #else - throw *e; +#define CPP_HAS_TRY_CATCH 1 #endif #else if (e) cerr << e->message << endl; exit(0); #endif -} -#define THROWS(s) +#ifndef CPP_HAS_TRY_CATCH +#define CPP_HAS_TRY_CATCH 0 +#define NCURSES_CPP_TRY /* nothing */ +#define NCURSES_CPP_CATCH(e) if (false) +#define THROWS(s) /* nothing */ +#elif CPP_HAS_TRY_CATCH + throw *e; +#define NCURSES_CPP_TRY try +#define NCURSES_CPP_CATCH(e) catch(e) +#define THROWS(s) throw(s) +#endif +} #endif /* NCURSES_ETIP_H_incl */ --- include/ncurses_defs +++ include/ncurses_defs 2007-04-07 00:54:16.000000000 +0200 @@ -68,6 +68,7 @@ HAVE_GPM_H HAVE_GPP_BUILTIN_H HAVE_GXX_BUILTIN_H HAVE_HAS_KEY +HAVE_IOSTREAM HAVE_ISASCII HAVE_ISSETUGID HAVE_LANGINFO_CODESET --- ncurses/base/lib_addstr.c +++ ncurses/base/lib_addstr.c 2007-04-04 02:41:25.000000000 +0200 @@ -80,8 +80,7 @@ waddnstr(WINDOW *win, const char *astr, NCURSES_EXPORT(int) waddchnstr(WINDOW *win, const chtype *astr, int n) { - NCURSES_SIZE_T y = win->_cury; - NCURSES_SIZE_T x = win->_curx; + NCURSES_SIZE_T y, x; int code = OK; int i; struct ldat *line; @@ -91,6 +90,8 @@ waddchnstr(WINDOW *win, const chtype *as if (!win) returnCode(ERR); + y = win->_cury; + x = win->_curx; if (n < 0) { const chtype *str; n = 0; --- ncurses/base/lib_color.c +++ ncurses/base/lib_color.c 2007-04-04 22:32:04.000000000 +0200 @@ -56,7 +56,10 @@ NCURSES_EXPORT_VAR(int) COLORS = 0; #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts)) +#define MAX_PALETTE 8 + #define OkColorHi(n) (((n) < COLORS) && ((n) < max_colors)) +#define InPalette(n) ((n) >= 0 && (n) < MAX_PALETTE) /* * Given a RGB range of 0..1000, we'll normally set the individual values @@ -162,10 +165,10 @@ init_color_table(void) tp = (hue_lightness_saturation) ? hls_palette : cga_palette; for (n = 0; n < COLORS; n++) { - if (n < 8) { + if (InPalette(n)) { SP->_color_table[n] = tp[n]; } else { - SP->_color_table[n] = tp[n % 8]; + SP->_color_table[n] = tp[n % MAX_PALETTE]; if (hue_lightness_saturation) { SP->_color_table[n].green = 100; } else { @@ -365,7 +368,7 @@ init_pair(short pair, short f, short b) if (GET_SCREEN_PAIR(SP) == pair) SET_SCREEN_PAIR(SP, (chtype) (~0)); /* force attribute update */ - if (initialize_pair) { + if (initialize_pair && InPalette(f) && InPalette(b)) { const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; TR(TRACE_ATTRS, --- ncurses/base/lib_overlay.c +++ ncurses/base/lib_overlay.c 2007-04-04 02:40:12.000000000 +0200 @@ -139,8 +139,8 @@ copywin(const WINDOW *src, WINDOW *dst, { int sx, sy, dx, dy; bool touched; - attr_t bk = AttrOf(dst->_nc_bkgd); - attr_t mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0); + attr_t bk; + attr_t mask; T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"), src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); @@ -148,6 +148,9 @@ copywin(const WINDOW *src, WINDOW *dst, if (!src || !dst) returnCode(ERR); + bk = AttrOf(dst->_nc_bkgd); + mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0); + /* make sure rectangle exists in source */ if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) || (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) { --- ncurses/base/tries.c +++ ncurses/base/tries.c 2007-04-03 22:58:30.000000000 +0200 @@ -68,7 +68,7 @@ _nc_expand_try(TRIES * tree, unsigned co } } if (result != 0) { - if ((result[len] = ptr->ch) == 0) + if (ptr != 0 && (result[len] = ptr->ch) == 0) *((unsigned char *) (result + len)) = 128; #ifdef TRACE if (len == 0 && _nc_tracing != 0) --- ncurses/base/wresize.c +++ ncurses/base/wresize.c 2007-04-04 22:28:42.000000000 +0200 @@ -38,7 +38,7 @@ static int cleanup_lines(struct ldat *data, int length) { while (--length >= 0) - free(data->text); + free(data[length].text); free(data); return ERR; } --- ncurses/tinfo/trim_sgr0.c +++ ncurses/tinfo/trim_sgr0.c 2007-04-04 21:29:01.000000000 +0200 @@ -247,9 +247,7 @@ _nc_trim_sgr0(TERMTYPE *tp) if (!rewrite_sgr(on, enter_alt_charset_mode) || !rewrite_sgr(off, exit_alt_charset_mode) || !rewrite_sgr(end, exit_alt_charset_mode)) { - FreeIfNeeded(on); FreeIfNeeded(off); - FreeIfNeeded(end); } else if (similar_sgr(off, end) && !similar_sgr(off, on)) { TR(TRACE_DATABASE, ("adjusting sgr(9:off) : %s", _nc_visbuf(off))); @@ -315,8 +313,8 @@ _nc_trim_sgr0(TERMTYPE *tp) */ free(off); } - free(end); - free(on); + FreeIfNeeded(end); + FreeIfNeeded(on); } else { /* * Possibly some applications are confused if sgr0 contains rmacs, --- progs/dump_entry.c +++ progs/dump_entry.c 2007-04-07 17:51:47.000000000 +0200 @@ -352,14 +352,17 @@ version_filter(PredType type, PredIdx id } break; +#define is_termcap(type) (idx < (int) sizeof(type##_from_termcap) && \ + type##_from_termcap[idx]) + case V_BSD: /* BSD */ switch (type) { case BOOLEAN: - return bool_from_termcap[idx]; + return is_termcap(bool); case NUMBER: - return num_from_termcap[idx]; + return is_termcap(num); case STRING: - return str_from_termcap[idx]; + return is_termcap(str); } break; } @@ -788,11 +791,11 @@ fmt_entry(TERMTYPE *tterm, * Much more work should be done on this to support dumping termcaps. */ if (tversion == V_HPUX) { - if (memory_lock) { + if (VALID_STRING(memory_lock)) { (void) sprintf(buffer, "meml=%s", memory_lock); WRAP_CONCAT; } - if (memory_unlock) { + if (VALID_STRING(memory_unlock)) { (void) sprintf(buffer, "memu=%s", memory_unlock); WRAP_CONCAT; } --- progs/infocmp.c +++ progs/infocmp.c 2007-04-04 02:51:49.000000000 +0200 @@ -1084,7 +1084,6 @@ dump_initializers(TERMTYPE *term) } *tp++ = '"'; *tp = '\0'; - size += (strlen(term->Strings[n]) + 1); (void) printf("static char %-20s[] = %s;\n", string_variable(ExtStrname(term, n, strnames)), buf); } --- progs/tic.c +++ progs/tic.c 2007-04-07 17:20:35.000000000 +0200 @@ -353,11 +353,24 @@ 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 const char ** +static char ** make_namelist(char *src) { - const char **dst = 0; + char **dst = 0; char *s, *base; unsigned pass, n, nn; @@ -374,11 +387,13 @@ make_namelist(char *src) if ((s = stripped(buffer)) != 0) { if (dst != 0) dst[nn] = s; + else + free(s); nn++; } } if (pass == 1) { - dst = typeCalloc(const char *, nn + 1); + dst = typeCalloc(char *, nn + 1); rewind(fp); } } @@ -401,10 +416,10 @@ make_namelist(char *src) break; } if (pass == 1) - dst = typeCalloc(const char *, nn + 1); + dst = typeCalloc(char *, nn + 1); } } - if (showsummary) { + if (showsummary && (dst != 0)) { fprintf(log_fp, "Entries that will be compiled:\n"); for (n = 0; dst[n] != 0; n++) fprintf(log_fp, "%u:%s\n", n + 1, dst[n]); @@ -413,7 +428,7 @@ make_namelist(char *src) } static bool -matches(const char **needle, const char *haystack) +matches(char **needle, const char *haystack) /* does entry in needle list match |-separated field in haystack? */ { bool code = FALSE; @@ -468,7 +483,7 @@ main(int argc, char *argv[]) bool limited = TRUE; char *tversion = (char *) NULL; const char *source_file = "terminfo"; - const char **namelst = 0; + char **namelst = 0; char *outdir = (char *) NULL; bool check_only = FALSE; bool suppress_untranslatable = FALSE; @@ -784,6 +799,9 @@ main(int argc, char *argv[]) else fprintf(log_fp, "No entries written\n"); } +#if NO_LEAKS + free_namelist(namelst); +#endif cleanup(); ExitProgram(EXIT_SUCCESS); } --- tack/ansi.c +++ tack/ansi.c 2007-04-07 16:49:53.000000000 +0200 @@ -309,6 +309,8 @@ request_cfss(void) put_crlf(); for (i = 0; rqss[i].text; i++) { ptext(rqss[i].text); + if (rqss[i].expect == 0) + continue; j = strlen(rqss[i].text) + strlen(rqss[i].expect); putchp(' '); for (j++; j < 40; j++) @@ -600,10 +602,11 @@ tools_status( i = read_reports(); if (i != 'r' && i != 'R') { *ch = i; - return; + break; } } while (i); + /* VT320, VT420, etc. */ if (terminal_class >= 63) { do { i = request_cfss(); @@ -841,7 +844,7 @@ tools_charset( bank[j] = ch; if (ch < ' ' || ch > '/') break; - if (j + 1 >= (int) sizeof(bank)) + if (j + 2 >= (int) sizeof(bank)) break; } if (j == 1) --- tack/output.c +++ tack/output.c 2007-04-07 16:39:05.000000000 +0200 @@ -740,7 +740,9 @@ wait_here(void) /* ignore control S, but tell me about it */ while (ch == 023 || ch == 021) { ch = getchp(STRIP_PARITY); - if (i < (int) sizeof(cc)) + if (ch == EOF) + break; + if (i + 1 < (int) sizeof(cc)) cc[++i] = ch; } put_str("\nThe terminal sent a ^S -"); @@ -778,7 +780,7 @@ read_string( for (i = 0; i < length - 1; ) { ch = getchp(STRIP_PARITY); - if (ch == '\r' || ch == '\n') { + if (ch == '\r' || ch == '\n' || ch == EOF) { break; } if (ch == '\b' || ch == 127) { --- test/bs.c +++ test/bs.c 2007-04-03 01:14:05.000000000 +0200 @@ -459,7 +459,7 @@ initgame(void) do { c = getch(); } while - (!strchr("hjklrR", c) || c == FF); + (!(strchr("hjklrR", c) || c == FF)); if (c == FF) { (void) clearok(stdscr, TRUE); --- test/cardfile.c +++ test/cardfile.c 2007-04-04 22:12:24.000000000 +0200 @@ -136,13 +136,15 @@ add_content(CARD * card, const char *con if ((offset = strlen(card->content)) != 0) { total += 1 + offset; card->content = (char *) realloc(card->content, total + 1); - strcpy(card->content + offset++, " "); + if (card->content) + strcpy(card->content + offset++, " "); } else { if (card->content != 0) free(card->content); card->content = (char *) malloc(total + 1); } - strcpy(card->content + offset, content); + if (card->content) + strcpy(card->content + offset, content); } } --- test/demo_defkey.c +++ test/demo_defkey.c 2007-04-03 01:17:56.000000000 +0200 @@ -143,13 +143,12 @@ really_define_key(WINDOW *win, const cha code_name); } log_last_line(win); + if (vis_string != 0) { free(vis_string); vis_string = 0; } - if (vis_string != 0) - free(vis_string); vis_string = visible(new_string); if ((rc = key_defined(new_string)) > 0) { wprintw(win, "%s was bound to %s\n", vis_string, keyname(rc));