From 91494ab0071e71177728916199a406768f5ef963 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 25 Jun 2023 00:38:02 +0000 Subject: [PATCH] ncurses 6.4 - patch 20230624 + fixes for out-of-memory condition (report by "eaglegai"). --- NEWS | 5 +- VERSION | 2 +- dist.mk | 4 +- ncurses/base/key_defined.c | 7 ++- ncurses/base/tries.c | 7 ++- ncurses/curses.priv.h | 37 +++++++++---- ncurses/tinfo/access.c | 6 +- ncurses/tinfo/add_tries.c | 7 ++- ncurses/tinfo/comp_hash.c | 18 +++--- ncurses/tinfo/db_iterator.c | 11 ++-- ncurses/tinfo/lib_setup.c | 9 ++- ncurses/tinfo/lib_tparm.c | 31 +++++++---- ncurses/tinfo/obsolete.c | 95 +++++++++++++++++++++++++++++++- ncurses/tinfo/read_entry.c | 5 +- ncurses/tinfo/read_termcap.c | 16 +++--- ncurses/trace/lib_tracedmp.c | 8 +-- ncurses/trace/trace_buf.c | 10 +++- ncurses/trace/varargs.c | 12 ++-- ncurses/tty/hardscroll.c | 12 +++- ncurses/tty/lib_mvcur.c | 8 +-- package/debian-mingw/changelog | 4 +- package/debian-mingw64/changelog | 4 +- package/debian/changelog | 4 +- package/mingw-ncurses.nsi | 4 +- package/mingw-ncurses.spec | 2 +- package/ncurses.spec | 2 +- package/ncursest.spec | 2 +- test/demo_defkey.c | 8 +-- test/list_keys.c | 16 +++++- test/sp_tinfo.c | 12 ++-- test/test_setupterm.c | 13 ++++- 31 files changed, 268 insertions(+), 113 deletions(-) diff --git a/NEWS b/NEWS index b8147e20..dd032a57 100644 --- a/NEWS +++ b/NEWS @@ -26,7 +26,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.3967 2023/06/17 17:17:42 tom Exp $ +-- $Id: NEWS,v 1.3969 2023/06/24 22:59:35 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -46,6 +46,9 @@ 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. +20230624 + + fixes for out-of-memory condition (report by "eaglegai"). + 20230617 + markup manpages with revision information (prompted by discussion with Bjarni Ingi Gislason). diff --git a/VERSION b/VERSION index efbf785f..87165874 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5:0:10 6.4 20230617 +5:0:10 6.4 20230624 diff --git a/dist.mk b/dist.mk index fb55f3ae..999e3468 100644 --- a/dist.mk +++ b/dist.mk @@ -26,7 +26,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.1550 2023/06/17 09:47:23 tom Exp $ +# $Id: dist.mk,v 1.1551 2023/06/24 10:06:22 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -38,7 +38,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 6 NCURSES_MINOR = 4 -NCURSES_PATCH = 20230617 +NCURSES_PATCH = 20230624 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/ncurses/base/key_defined.c b/ncurses/base/key_defined.c index 25d5a674..147e5fe2 100644 --- a/ncurses/base/key_defined.c +++ b/ncurses/base/key_defined.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 2003-2006,2009 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -32,8 +32,9 @@ ****************************************************************************/ #include +#include -MODULE_ID("$Id: key_defined.c,v 1.10 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: key_defined.c,v 1.11 2023/06/24 15:36:32 tom Exp $") static int find_definition(TRIES * tree, const char *str) @@ -41,7 +42,7 @@ find_definition(TRIES * tree, const char *str) TRIES *ptr; int result = OK; - if (str != 0 && *str != '\0') { + if (VALID_STRING(str) && *str != '\0') { for (ptr = tree; ptr != 0; ptr = ptr->sibling) { if (UChar(*str) == UChar(ptr->ch)) { if (str[1] == '\0' && ptr->child != 0) { diff --git a/ncurses/base/tries.c b/ncurses/base/tries.c index 0f309c21..0f8c0516 100644 --- a/ncurses/base/tries.c +++ b/ncurses/base/tries.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 1998-2009,2010 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -39,8 +39,9 @@ */ #include +#include -MODULE_ID("$Id: tries.c,v 1.31 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: tries.c,v 1.32 2023/06/24 15:36:23 tom Exp $") /* * Expand a keycode into the string that it corresponds to, returning null if @@ -124,7 +125,7 @@ _nc_remove_string(TRIES ** tree, const char *string) { T((T_CALLED("_nc_remove_string(%p,%s)"), (void *) tree, _nc_visbuf(string))); - if (string == 0 || *string == 0) + if (!VALID_STRING(string) || *string == 0) returnCode(FALSE); while (*tree != 0) { diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index e7146ef7..3fd8e0d2 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -35,7 +35,7 @@ ****************************************************************************/ /* - * $Id: curses.priv.h,v 1.669 2023/06/06 22:31:04 tom Exp $ + * $Id: curses.priv.h,v 1.670 2023/06/24 13:00:26 tom Exp $ * * curses.priv.h * @@ -574,10 +574,10 @@ extern NCURSES_EXPORT(void) _nc_set_no_padding(SCREEN *); #define SET_SCREEN_PAIR(s,p) SetPair(SCREEN_ATTRS(s), p) #if USE_REENTRANT || NCURSES_SP_FUNCS -NCURSES_EXPORT(int *) _nc_ptr_Lines (SCREEN *); -NCURSES_EXPORT(int *) _nc_ptr_Cols (SCREEN *); -NCURSES_EXPORT(int *) _nc_ptr_Tabsize (SCREEN *); -NCURSES_EXPORT(int *) _nc_ptr_Escdelay (SCREEN *); +extern NCURSES_EXPORT(int *) _nc_ptr_Lines (SCREEN *); +extern NCURSES_EXPORT(int *) _nc_ptr_Cols (SCREEN *); +extern NCURSES_EXPORT(int *) _nc_ptr_Tabsize (SCREEN *); +extern NCURSES_EXPORT(int *) _nc_ptr_Escdelay (SCREEN *); #endif #if USE_REENTRANT @@ -1540,6 +1540,9 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #define SIZEOF(v) (sizeof(v)/sizeof(v[0])) +#include +#include + #define FreeIfNeeded(p) if ((p) != 0) free(p) /* FreeAndNull() is not a comma-separated expression because some compilers @@ -1547,8 +1550,18 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; */ #define FreeAndNull(p) do { free(p); p = 0; } while (0) -#include -#include +#ifdef EXP_OOM_TESTING +extern NCURSES_EXPORT(void *) _nc_oom_malloc(size_t size); +extern NCURSES_EXPORT(void *) _nc_oom_calloc(size_t nmemb, size_t size); +extern NCURSES_EXPORT(void *) _nc_oom_realloc(void *ptr, size_t size); +extern NCURSES_EXPORT(void) _nc_oom_free(void *ptr); +extern NCURSES_EXPORT(char *) _nc_oom_strdup(const char *ptr); +#define malloc(size) _nc_oom_malloc(size) +#define calloc(nmemb, size) _nc_oom_calloc(nmemb, size) +#define realloc(ptr, size) _nc_oom_realloc(ptr, size) +#define free(ptr) _nc_oom_free(ptr) +#define strdup(ptr) _nc_oom_strdup(ptr) +#endif /* * Use these for tic/infocmp malloc failures. Generally the ncurses library @@ -1968,7 +1981,7 @@ extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* lib_addch.c */ #if USE_WIDEC_SUPPORT -NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch); +extern NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch); #endif /* lib_addstr.c */ @@ -2147,7 +2160,7 @@ extern NCURSES_EXPORT(const TERMTYPE2 *) _nc_fallback2 (const char *); #define _nc_fallback2(tp) _nc_fallback(tp) #endif -NCURSES_EXPORT(void) _nc_copy_termtype(TERMTYPE *, const TERMTYPE *); +extern NCURSES_EXPORT(void) _nc_copy_termtype(TERMTYPE *, const TERMTYPE *); #if NCURSES_EXT_NUMBERS extern NCURSES_EXPORT(void) _nc_copy_termtype2 (TERMTYPE2 *, const TERMTYPE2 *); @@ -2229,7 +2242,7 @@ extern int __MINGW_NOTHROW _nc_mblen(const char *, size_t); #if defined(_NC_WINDOWS) || defined(_NC_MINGW) /* see wcwidth.c */ -NCURSES_EXPORT(int) mk_wcwidth(wchar_t); +extern NCURSES_EXPORT(int) mk_wcwidth(wchar_t); #define wcwidth(ucs) _nc_wcwidth(ucs) #endif @@ -2621,8 +2634,8 @@ extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype); #endif #ifdef EXP_XTERM_1005 -NCURSES_EXPORT(int) _nc_conv_to_utf8(unsigned char *, unsigned, unsigned); -NCURSES_EXPORT(int) _nc_conv_to_utf32(unsigned *, const char *, unsigned); +extern NCURSES_EXPORT(int) _nc_conv_to_utf8(unsigned char *, unsigned, unsigned); +extern NCURSES_EXPORT(int) _nc_conv_to_utf32(unsigned *, const char *, unsigned); #endif #ifdef __cplusplus diff --git a/ncurses/tinfo/access.c b/ncurses/tinfo/access.c index 6c415aca..50a5769c 100644 --- a/ncurses/tinfo/access.c +++ b/ncurses/tinfo/access.c @@ -52,7 +52,7 @@ #include -MODULE_ID("$Id: access.c,v 1.36 2023/04/22 21:19:56 tom Exp $") +MODULE_ID("$Id: access.c,v 1.37 2023/06/24 21:55:09 tom Exp $") #define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c)) @@ -70,8 +70,8 @@ _nc_rootname(char *path) static char *temp; char *s; - temp = strdup(result); - result = temp; + if ((temp = strdup(result)) != 0) + result = temp; #if !MIXEDCASE_FILENAMES for (s = result; *s != '\0'; ++s) { *s = (char) LOWERCASE(*s); diff --git a/ncurses/tinfo/add_tries.c b/ncurses/tinfo/add_tries.c index d41f4883..9d215575 100644 --- a/ncurses/tinfo/add_tries.c +++ b/ncurses/tinfo/add_tries.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2020,2023 Thomas E. Dickey * * Copyright 1998-2009,2010 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -39,8 +39,9 @@ */ #include +#include -MODULE_ID("$Id: add_tries.c,v 1.12 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: add_tries.c,v 1.13 2023/06/24 15:36:13 tom Exp $") #define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0' #define CMP_TRY(a,b) ((a)? (a == b) : (b == 128)) @@ -53,7 +54,7 @@ _nc_add_to_try(TRIES ** tree, const char *str, unsigned code) T((T_CALLED("_nc_add_to_try(%p, %s, %u)"), (void *) *tree, _nc_visbuf(str), code)); - if (txt == 0 || *txt == '\0' || code == 0) + if (!VALID_STRING(str) || *txt == '\0' || code == 0) returnCode(ERR); if ((*tree) != 0) { diff --git a/ncurses/tinfo/comp_hash.c b/ncurses/tinfo/comp_hash.c index eff60f12..4b081afa 100644 --- a/ncurses/tinfo/comp_hash.c +++ b/ncurses/tinfo/comp_hash.c @@ -45,7 +45,7 @@ #include #include -MODULE_ID("$Id: comp_hash.c,v 1.54 2023/04/22 15:12:57 tom Exp $") +MODULE_ID("$Id: comp_hash.c,v 1.55 2023/06/24 13:29:43 tom Exp $") /* * Finds the entry for the given string in the hash table if present. @@ -103,14 +103,16 @@ _nc_find_type_entry(const char *string, && data->table_data[hashvalue] >= 0) { const struct name_table_entry *const table = _nc_get_table(termcap); - ptr = table + data->table_data[hashvalue]; - while (ptr->nte_type != type - || !data->compare_names(ptr->nte_name, string)) { - if (ptr->nte_link < 0) { - ptr = 0; - break; + if (table != NULL) { + ptr = table + data->table_data[hashvalue]; + while (ptr->nte_type != type + || !data->compare_names(ptr->nte_name, string)) { + if (ptr->nte_link < 0) { + ptr = 0; + break; + } + ptr = table + (ptr->nte_link + data->table_data[data->table_size]); } - ptr = table + (ptr->nte_link + data->table_data[data->table_size]); } } diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c index e69e0f34..db3872e3 100644 --- a/ncurses/tinfo/db_iterator.c +++ b/ncurses/tinfo/db_iterator.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 2006-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -44,7 +44,7 @@ #include #endif -MODULE_ID("$Id: db_iterator.c,v 1.49 2022/04/23 20:03:15 tom Exp $") +MODULE_ID("$Id: db_iterator.c,v 1.50 2023/06/24 21:52:32 tom Exp $") #define HaveTicDirectory _nc_globals.have_tic_directory #define KeepTicDirectory _nc_globals.keep_tic_directory @@ -383,8 +383,11 @@ _nc_first_db(DBDIRS * state, int *offset) */ for (j = 0; my_list[j] != 0; ++j) { #ifdef TERMINFO - if (*my_list[j] == '\0') - my_list[j] = strdup(TERMINFO); + if (*my_list[j] == '\0') { + char *my_copy = strdup(TERMINFO); + if (my_copy != 0) + my_list[j] = my_copy; + } #endif trim_formatting(my_list[j]); for (k = 0; k < j; ++k) { diff --git a/ncurses/tinfo/lib_setup.c b/ncurses/tinfo/lib_setup.c index db93a368..cdc6726c 100644 --- a/ncurses/tinfo/lib_setup.c +++ b/ncurses/tinfo/lib_setup.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2021,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -49,7 +49,7 @@ #include #endif -MODULE_ID("$Id: lib_setup.c,v 1.218 2022/08/13 18:12:22 tom Exp $") +MODULE_ID("$Id: lib_setup.c,v 1.219 2023/06/24 13:25:14 tom Exp $") /**************************************************************************** * @@ -679,10 +679,9 @@ TINFO_SETUP_TERM(TERMINAL **tp, #endif } myname = strdup(tname); - - if (strlen(myname) > MAX_NAME_SIZE) { + if (myname == NULL || strlen(myname) > MAX_NAME_SIZE) { ret_error(TGETENT_ERR, - "TERM environment must be <= %d characters.\n", + "TERM environment must be 1..%d characters.\n", MAX_NAME_SIZE, free(myname)); } diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c index 93af8350..0d6d7b3c 100644 --- a/ncurses/tinfo/lib_tparm.c +++ b/ncurses/tinfo/lib_tparm.c @@ -53,7 +53,7 @@ #include #include -MODULE_ID("$Id: lib_tparm.c,v 1.146 2023/04/23 20:57:33 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.150 2023/06/24 16:12:52 tom Exp $") /* * char * @@ -177,19 +177,21 @@ _nc_free_tparm(TERMINAL *termp) #if HAVE_TSEARCH if (MyCount != 0) { delete_tparm = typeCalloc(TPARM_DATA *, MyCount); - which_tparm = 0; - twalk(MyCache, visit_nodes); - for (which_tparm = 0; which_tparm < MyCount; ++which_tparm) { - TPARM_DATA *ptr = delete_tparm[which_tparm]; - if (ptr != NULL) { - tdelete(ptr, &MyCache, cmp_format); - free((char *) ptr->format); - free(ptr); + if (delete_tparm != NULL) { + which_tparm = 0; + twalk(MyCache, visit_nodes); + for (which_tparm = 0; which_tparm < MyCount; ++which_tparm) { + TPARM_DATA *ptr = delete_tparm[which_tparm]; + if (ptr != NULL) { + tdelete(ptr, &MyCache, cmp_format); + free((char *) ptr->format); + free(ptr); + } } + which_tparm = 0; + twalk(MyCache, visit_nodes); + FreeAndNull(delete_tparm); } - which_tparm = 0; - twalk(MyCache, visit_nodes); - FreeAndNull(delete_tparm); MyCount = 0; which_tparm = 0; } @@ -796,6 +798,11 @@ tparam_internal(TPARM_STATE *tps, const char *string, TPARM_DATA *data) tparm_trace_call(tps, string, data); + if (TPS(fmt_buff) == NULL) { + T((T_RETURN(""))); + return NULL; + } + while ((cp - string) < (int) len2) { if (*cp != '%') { save_char(tps, UChar(*cp)); diff --git a/ncurses/tinfo/obsolete.c b/ncurses/tinfo/obsolete.c index 972a9a18..e63f8a86 100644 --- a/ncurses/tinfo/obsolete.c +++ b/ncurses/tinfo/obsolete.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 2013-2014,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -37,7 +37,7 @@ #include -MODULE_ID("$Id: obsolete.c,v 1.6 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: obsolete.c,v 1.9 2023/06/24 22:02:25 tom Exp $") /* * Obsolete entrypoint retained for binary compatibility. @@ -238,3 +238,94 @@ _nc_conv_to_utf32(unsigned *target, const char *source, unsigned limit) #undef CH } #endif /* EXP_XTERM_1005 */ + +#ifdef EXP_OOM_TESTING +/* + * Out-of-memory testing, suitable for checking if initialization (and limited + * running) recovers from errors due to insufficient memory. In practice, this + * is unlikely except with artifically constructed tests (or poorly behaved + * applications). + */ +#undef malloc +#undef calloc +#undef realloc +#undef free +#undef strdup + +static long oom_limit = -1; +static long oom_count = 0; + +static bool +oom_check(void) +{ + static bool initialized = FALSE; + static bool triggered = FALSE; + bool result = FALSE; + + if (!initialized) { + char *env = getenv("NCURSES_OOM_TESTING"); + initialized = TRUE; + if (env != NULL) { + char *check; + oom_limit = strtol(env, &check, 0); + if (check != NULL && *check != '\0') + oom_limit = 0; + } + } + if (oom_limit >= 0) { + result = (++oom_count > oom_limit); + if (result && !triggered) { + triggered = TRUE; + T(("out-of-memory")); + } + } + return result; +} + +NCURSES_EXPORT(void *) +_nc_oom_malloc(size_t size) +{ + char *result = (oom_check() + ? NULL + : malloc(size)); + T(("oom #%ld malloc(%ld) %p", oom_count, size, result)); + return result; +} + +NCURSES_EXPORT(void *) +_nc_oom_calloc(size_t nmemb, size_t size) +{ + char *result = (oom_check() + ? NULL + : calloc(nmemb, size)); + T(("oom #%ld calloc(%ld, %ld) %p", oom_count, nmemb, size, result)); + return result; +} + +NCURSES_EXPORT(void *) +_nc_oom_realloc(void *ptr, size_t size) +{ + char *result = (oom_check() + ? NULL + : realloc(ptr, size)); + T(("oom #%ld realloc(%p, %ld) %p", oom_count, ptr, size, result)); + return result; +} + +NCURSES_EXPORT(void) +_nc_oom_free(void *ptr) +{ + T(("oom #%ld free(%p)", oom_count, ptr)); + free(ptr); +} + +NCURSES_EXPORT(char *) +_nc_oom_strdup(const char *ptr) +{ + char *result = (oom_check() + ? NULL + : strdup(ptr)); + T(("oom #%ld strdup(%p) %p", oom_count, ptr, result)); + return result; +} +#endif /* EXP_OOM_TESTING */ diff --git a/ncurses/tinfo/read_entry.c b/ncurses/tinfo/read_entry.c index 762c6c68..3591a508 100644 --- a/ncurses/tinfo/read_entry.c +++ b/ncurses/tinfo/read_entry.c @@ -42,7 +42,7 @@ #include -MODULE_ID("$Id: read_entry.c,v 1.169 2023/06/15 20:51:06 tom Exp $") +MODULE_ID("$Id: read_entry.c,v 1.170 2023/06/24 18:09:05 tom Exp $") #define MyNumber(n) (short) LOW_MSB(n) @@ -803,6 +803,9 @@ _nc_read_tic_entry(char *filename, int reccnt = 0; char *save = strdup(name); + if (save == 0) + returnDB(code); + memset(&key, 0, sizeof(key)); key.data = save; key.size = strlen(save); diff --git a/ncurses/tinfo/read_termcap.c b/ncurses/tinfo/read_termcap.c index 9ff2b2ba..1a294848 100644 --- a/ncurses/tinfo/read_termcap.c +++ b/ncurses/tinfo/read_termcap.c @@ -57,7 +57,7 @@ #include #include -MODULE_ID("$Id: read_termcap.c,v 1.103 2023/04/28 20:59:14 tom Exp $") +MODULE_ID("$Id: read_termcap.c,v 1.104 2023/06/24 21:53:16 tom Exp $") #if !PURE_TERMINFO @@ -1055,15 +1055,15 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE2 *const tp) if (normal) { /* normal case */ char envhome[PATH_MAX], *h; - copied = strdup(get_termpath()); - for (cp = copied; *cp; cp++) { - if (*cp == NCURSES_PATHSEP) - *cp = '\0'; - else if (cp == copied || cp[-1] == '\0') { - ADD_TC(cp, filecount); + if ((copied = strdup(get_termpath())) != 0) { + for (cp = copied; *cp; cp++) { + if (*cp == NCURSES_PATHSEP) + *cp = '\0'; + else if (cp == copied || cp[-1] == '\0') { + ADD_TC(cp, filecount); + } } } - #define PRIVATE_CAP "%.*s/.termcap" if (use_terminfo_vars() && (h = getenv("HOME")) != NULL && *h != '\0' diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c index 3b7ea074..529148bb 100644 --- a/ncurses/trace/lib_tracedmp.c +++ b/ncurses/trace/lib_tracedmp.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 1998-2012,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -40,7 +40,7 @@ #include #include -MODULE_ID("$Id: lib_tracedmp.c,v 1.36 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: lib_tracedmp.c,v 1.37 2023/06/24 15:49:45 tom Exp $") #ifdef TRACE @@ -71,9 +71,9 @@ _tracedump(const char *name, WINDOW *win) if (++width + 1 > (int) my_length) { my_length = (unsigned) (2 * (width + 1)); my_buffer = typeRealloc(char, my_length, my_buffer); - if (my_buffer == 0) - return; } + if (my_buffer == 0) + return; for (n = 0; n <= win->_maxy; ++n) { char *ep = my_buffer; diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c index 7e6384b5..91b12e45 100644 --- a/ncurses/trace/trace_buf.c +++ b/ncurses/trace/trace_buf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 1998-2011,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -36,7 +36,7 @@ #include -MODULE_ID("$Id: trace_buf.c,v 1.21 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: trace_buf.c,v 1.22 2023/06/24 13:37:25 tom Exp $") #ifdef TRACE @@ -104,7 +104,11 @@ _nc_trace_buf(int bufnum, size_t want) NCURSES_EXPORT(char *) _nc_trace_bufcat(int bufnum, const char *value) { - char *buffer = _nc_trace_alloc(bufnum, (size_t) 0); + char *buffer; + + if (value == NULL) + value = ""; + buffer = _nc_trace_alloc(bufnum, (size_t) 0); if (buffer != 0) { size_t have = strlen(buffer); size_t need = strlen(value) + have; diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c index 9be5fc25..7b9533bd 100644 --- a/ncurses/trace/varargs.c +++ b/ncurses/trace/varargs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 2001-2008,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -35,7 +35,7 @@ #include -MODULE_ID("$Id: varargs.c,v 1.12 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: varargs.c,v 1.13 2023/06/24 13:41:46 tom Exp $") #ifdef TRACE @@ -59,18 +59,16 @@ typedef enum { NCURSES_EXPORT(char *) _nc_varargs(const char *fmt, va_list ap) { - static char dummy[] = ""; - char buffer[BUFSIZ]; const char *param; int n; if (fmt == 0 || *fmt == '\0') - return dummy; + return NULL; if (MyLength == 0) MyBuffer = typeMalloc(char, MyLength = BUFSIZ); if (MyBuffer == 0) - return dummy; + return NULL; *MyBuffer = '\0'; while (*fmt != '\0') { @@ -185,7 +183,7 @@ _nc_varargs(const char *fmt, va_list ap) } } - return (MyBuffer ? MyBuffer : dummy); + return (MyBuffer ? MyBuffer : NULL); } #else EMPTY_MODULE(_nc_varargs) diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c index abb21cfd..d66aa994 100644 --- a/ncurses/tty/hardscroll.c +++ b/ncurses/tty/hardscroll.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020 Thomas E. Dickey * + * Copyright 2020,2023 Thomas E. Dickey * * Copyright 1998-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -148,7 +148,7 @@ AUTHOR #include -MODULE_ID("$Id: hardscroll.c,v 1.54 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: hardscroll.c,v 1.56 2023/06/24 22:55:24 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -204,13 +204,19 @@ NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_DCL0) int *new_oldnums = typeRealloc(int, (size_t) need_lines, oldnums(SP_PARM)); - if (!new_oldnums) + if (!new_oldnums) { + TR(TRACE_ICALLS, (T_RETURN(""))); return; + } oldnums(SP_PARM) = new_oldnums; OLDNUM_SIZE(SP_PARM) = need_lines; } /* calculate the indices */ NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_ARG); + if (SP_PARM->hashtab_len < screen_lines(SP_PARM)) { + TR(TRACE_ICALLS, (T_RETURN(""))); + return; + } #endif #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ diff --git a/ncurses/tty/lib_mvcur.c b/ncurses/tty/lib_mvcur.c index ba3ee089..aa3a67c5 100644 --- a/ncurses/tty/lib_mvcur.c +++ b/ncurses/tty/lib_mvcur.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2021,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -160,7 +160,7 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_mvcur.c,v 1.157 2022/08/20 18:28:58 tom Exp $") +MODULE_ID("$Id: lib_mvcur.c,v 1.158 2023/06/24 17:34:43 tom Exp $") #define WANT_CHAR(sp, y, x) NewScreen(sp)->_line[y].text[x] /* desired state */ @@ -675,7 +675,7 @@ relative_move(NCURSES_SP_DCLx * and the time the structure WANT_CHAR would access has been * updated. */ - if (ovw) { + if (ovw && to_y >= 0) { int i; for (i = 0; i < n; i++) { @@ -690,7 +690,7 @@ relative_move(NCURSES_SP_DCLx } } } - if (ovw) { + if (ovw && to_y >= 0) { int i; for (i = 0; i < n; i++) diff --git a/package/debian-mingw/changelog b/package/debian-mingw/changelog index 91a84956..4356b0eb 100644 --- a/package/debian-mingw/changelog +++ b/package/debian-mingw/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.4+20230617) unstable; urgency=low +ncurses6 (6.4+20230624) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 17 Jun 2023 05:47:23 -0400 + -- Thomas E. Dickey Sat, 24 Jun 2023 06:06:22 -0400 ncurses6 (5.9+20131005) unstable; urgency=low diff --git a/package/debian-mingw64/changelog b/package/debian-mingw64/changelog index 91a84956..4356b0eb 100644 --- a/package/debian-mingw64/changelog +++ b/package/debian-mingw64/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.4+20230617) unstable; urgency=low +ncurses6 (6.4+20230624) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 17 Jun 2023 05:47:23 -0400 + -- Thomas E. Dickey Sat, 24 Jun 2023 06:06:22 -0400 ncurses6 (5.9+20131005) unstable; urgency=low diff --git a/package/debian/changelog b/package/debian/changelog index 95e7bef9..8783d4d0 100644 --- a/package/debian/changelog +++ b/package/debian/changelog @@ -1,8 +1,8 @@ -ncurses6 (6.4+20230617) unstable; urgency=low +ncurses6 (6.4+20230624) unstable; urgency=low * latest weekly patch - -- Thomas E. Dickey Sat, 17 Jun 2023 05:47:23 -0400 + -- Thomas E. Dickey Sat, 24 Jun 2023 06:06:22 -0400 ncurses6 (5.9+20120608) unstable; urgency=low diff --git a/package/mingw-ncurses.nsi b/package/mingw-ncurses.nsi index 27eeed77..7abb6160 100644 --- a/package/mingw-ncurses.nsi +++ b/package/mingw-ncurses.nsi @@ -1,4 +1,4 @@ -; $Id: mingw-ncurses.nsi,v 1.590 2023/06/17 09:47:23 tom Exp $ +; $Id: mingw-ncurses.nsi,v 1.591 2023/06/24 10:06:22 tom Exp $ ; TODO add examples ; TODO bump ABI to 6 @@ -10,7 +10,7 @@ !define VERSION_MAJOR "6" !define VERSION_MINOR "4" !define VERSION_YYYY "2023" -!define VERSION_MMDD "0617" +!define VERSION_MMDD "0624" !define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD} !define MY_ABI "5" diff --git a/package/mingw-ncurses.spec b/package/mingw-ncurses.spec index 6f006b0d..82240292 100644 --- a/package/mingw-ncurses.spec +++ b/package/mingw-ncurses.spec @@ -3,7 +3,7 @@ Summary: shared libraries for terminal handling Name: mingw32-ncurses6 Version: 6.4 -Release: 20230617 +Release: 20230624 License: X11 Group: Development/Libraries URL: https://invisible-island.net/ncurses/ diff --git a/package/ncurses.spec b/package/ncurses.spec index b3ee6442..8b541eea 100644 --- a/package/ncurses.spec +++ b/package/ncurses.spec @@ -1,7 +1,7 @@ Summary: shared libraries for terminal handling Name: ncurses6 Version: 6.4 -Release: 20230617 +Release: 20230624 License: X11 Group: Development/Libraries URL: https://invisible-island.net/ncurses/ diff --git a/package/ncursest.spec b/package/ncursest.spec index 11d3e1d1..dc459b77 100644 --- a/package/ncursest.spec +++ b/package/ncursest.spec @@ -1,7 +1,7 @@ Summary: Curses library with POSIX thread support. Name: ncursest6 Version: 6.4 -Release: 20230617 +Release: 20230624 License: X11 Group: Development/Libraries Source: ncurses-%{version}-%{release}.tgz diff --git a/test/demo_defkey.c b/test/demo_defkey.c index 44d60dc9..bb812638 100644 --- a/test/demo_defkey.c +++ b/test/demo_defkey.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 2002-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_defkey.c,v 1.33 2022/12/10 23:31:31 tom Exp $ + * $Id: demo_defkey.c,v 1.34 2023/06/24 15:37:17 tom Exp $ * * Demonstrate the define_key() function. * Thomas Dickey - 2002/11/23 @@ -100,7 +100,7 @@ visible(const char *string) { char *result = 0; - if (string != 0 && *string != '\0') { + if (VALID_STRING(string) && *string != '\0') { int pass; int n; size_t need = 1; @@ -185,7 +185,7 @@ duplicate(WINDOW *win, NCURSES_CONST char *name, int code) { char *value = tigetstr(name); - if (value != 0) { + if (VALID_STRING(value)) { const char *prefix = 0; if (!(strncmp) (value, "\033[", (size_t) 2)) { diff --git a/test/list_keys.c b/test/list_keys.c index ee54b856..96b02e14 100644 --- a/test/list_keys.c +++ b/test/list_keys.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2021,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: list_keys.c,v 1.31 2022/12/10 23:23:27 tom Exp $ + * $Id: list_keys.c,v 1.32 2023/06/24 13:57:11 tom Exp $ * * Author: Thomas E Dickey * @@ -71,6 +71,13 @@ typedef struct { #define Type(n) list[n].type #define Name(n) list[n].name +static void +failed(const char *msg) +{ + perror(msg); + ExitProgram(EXIT_FAILURE); +} + static const char * full_name(const char *name) { @@ -338,8 +345,11 @@ list_keys(TERMINAL **terms, int count) widths1 = (int) strlen(modifier); for (k = 0; k < count; ++k) { + char *value; set_curterm(terms[k]); - check = (int) strlen(termname()); + if ((value = termname()) == NULL) + failed("termname"); + check = (int) strlen(value); if (widths2 < check) widths2 = check; } diff --git a/test/sp_tinfo.c b/test/sp_tinfo.c index d003dfa3..72b20cfb 100644 --- a/test/sp_tinfo.c +++ b/test/sp_tinfo.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019-2020,2022 Thomas E. Dickey * + * Copyright 2019-2022,2023 Thomas E. Dickey * * Copyright 2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -28,7 +28,7 @@ ****************************************************************************/ /* - * $Id: sp_tinfo.c,v 1.28 2022/12/10 23:23:27 tom Exp $ + * $Id: sp_tinfo.c,v 1.29 2023/06/24 14:14:56 tom Exp $ * * TOTO: add option for non-sp-funcs interface */ @@ -339,8 +339,12 @@ main(int argc, char *argv[]) do_stuff(my_out); do_stuff(my_err); - cleanup(my_out); - cleanup(my_err); + if (my_out != my_err) { + cleanup(my_out); + cleanup(my_err); + } else { + cleanup(my_out); + } ExitProgram(EXIT_SUCCESS); } diff --git a/test/test_setupterm.c b/test/test_setupterm.c index 4e53c2e7..24d7c46c 100644 --- a/test/test_setupterm.c +++ b/test/test_setupterm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020,2022 Thomas E. Dickey * + * Copyright 2020-2022,2023 Thomas E. Dickey * * Copyright 2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -30,7 +30,7 @@ /* * Author: Thomas E. Dickey * - * $Id: test_setupterm.c,v 1.16 2022/12/10 23:23:27 tom Exp $ + * $Id: test_setupterm.c,v 1.17 2023/06/24 14:19:52 tom Exp $ * * A simple demo of setupterm/restartterm. */ @@ -48,6 +48,13 @@ static TERMINAL **saved_terminals; static size_t num_saved; static size_t max_saved; +static void +failed(const char *msg) +{ + perror(msg); + ExitProgram(EXIT_FAILURE); +} + static void finish(int code) { @@ -73,6 +80,8 @@ save_curterm(void) if (num_saved + 1 >= max_saved) { max_saved += 100; saved_terminals = typeRealloc(TERMINAL *, max_saved, saved_terminals); + if (saved_terminals == NULL) + failed("realloc"); } saved_terminals[num_saved++] = cur_term; } -- 2.45.0