summaryrefslogtreecommitdiff
path: root/ncurses/tinfo/alloc_ttype.c
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/tinfo/alloc_ttype.c')
-rw-r--r--ncurses/tinfo/alloc_ttype.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/ncurses/tinfo/alloc_ttype.c b/ncurses/tinfo/alloc_ttype.c
index 304c1b62f4e6..cb711f484277 100644
--- a/ncurses/tinfo/alloc_ttype.c
+++ b/ncurses/tinfo/alloc_ttype.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2022,2023 Thomas E. Dickey *
+ * Copyright 2018-2024,2025 Thomas E. Dickey *
* Copyright 1999-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <tic.h>
-MODULE_ID("$Id: alloc_ttype.c,v 1.51 2023/09/09 23:15:53 tom Exp $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.55 2025/02/16 18:31:37 tom Exp $")
#if NCURSES_XNAMES
/*
@@ -181,7 +181,7 @@ realign_data(TERMTYPE2 *to, char **ext_Names,
* Returns the first index in ext_Names[] for the given token-type
*/
static unsigned
-_nc_first_ext_name(TERMTYPE2 *tp, int token_type)
+_nc_first_ext_name(const TERMTYPE2 *tp, int token_type)
{
unsigned first;
@@ -206,7 +206,7 @@ _nc_first_ext_name(TERMTYPE2 *tp, int token_type)
* Returns the last index in ext_Names[] for the given token-type
*/
static unsigned
-_nc_last_ext_name(TERMTYPE2 *tp, int token_type)
+_nc_last_ext_name(const TERMTYPE2 *tp, int token_type)
{
unsigned last;
@@ -229,15 +229,17 @@ _nc_last_ext_name(TERMTYPE2 *tp, int token_type)
* Lookup an entry from extended-names, returning -1 if not found
*/
static int
-_nc_find_ext_name(TERMTYPE2 *tp, char *name, int token_type)
+_nc_find_ext_name(const TERMTYPE2 *tp, const char *name, int token_type)
{
- unsigned j;
- unsigned first = _nc_first_ext_name(tp, token_type);
- unsigned last = _nc_last_ext_name(tp, token_type);
+ if (name != NULL) {
+ unsigned j;
+ unsigned first = _nc_first_ext_name(tp, token_type);
+ unsigned last = _nc_last_ext_name(tp, token_type);
- for (j = first; j < last; j++) {
- if (!strcmp(name, tp->ext_Names[j])) {
- return (int) j;
+ for (j = first; j < last; j++) {
+ if (!strcmp(name, tp->ext_Names[j])) {
+ return (int) j;
+ }
}
}
return -1;
@@ -248,7 +250,7 @@ _nc_find_ext_name(TERMTYPE2 *tp, char *name, int token_type)
* (e.g., Booleans[]).
*/
static int
-_nc_ext_data_index(TERMTYPE2 *tp, int n, int token_type)
+_nc_ext_data_index(const TERMTYPE2 *tp, int n, int token_type)
{
switch (token_type) {
case BOOLEAN:
@@ -271,7 +273,7 @@ _nc_ext_data_index(TERMTYPE2 *tp, int n, int token_type)
* data.
*/
static bool
-_nc_del_ext_name(TERMTYPE2 *tp, char *name, int token_type)
+_nc_del_ext_name(TERMTYPE2 *tp, const char *name, int token_type)
{
int first;
@@ -381,9 +383,12 @@ adjust_cancels(TERMTYPE2 *to, TERMTYPE2 *from)
NonNull(to->term_names),
NonNull(from->term_names)));
for (j = first; j < last;) {
- char *name = to->ext_Names[j];
+ char *name;
int j_str = to->num_Strings - first - to->ext_Strings;
+ if ((j + j_str) > NUM_STRINGS(to))
+ break;
+ name = to->ext_Names[j];
if (to->Strings[j + j_str] == CANCELLED_STRING) {
if (_nc_find_ext_name(from, to->ext_Names[j], BOOLEAN) >= 0) {
if (_nc_del_ext_name(to, name, STRING)
@@ -532,8 +537,8 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
char *new_table;
size_t new_table_size;
#if NCURSES_EXT_NUMBERS
- short *oldptr = 0;
- int *newptr = 0;
+ short *oldptr = NULL;
+ int *newptr = NULL;
#endif
DEBUG(2, (T_CALLED("copy_termtype(dst=%p, src=%p, mode=%d)"), (void *)
@@ -594,7 +599,7 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
TYPE_MALLOC(int, NUM_NUMBERS(dst), newptr);
dst->Numbers = newptr;
}
- if ((mode == srcINT) && (oldptr != 0)) {
+ if ((mode == srcINT) && (oldptr != NULL)) {
DEBUG(2, ("...copy int ->short"));
for (i = 0; i < NUM_NUMBERS(dst); ++i) {
if (src->Numbers[i] > MAX_OF_TYPE(short)) {
@@ -603,7 +608,7 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
oldptr[i] = (short) src->Numbers[i];
}
}
- } else if ((mode == dstINT) && (newptr != 0)) {
+ } else if ((mode == dstINT) && (newptr != NULL)) {
DEBUG(2, ("...copy short ->int"));
for (i = 0; i < NUM_NUMBERS(dst); ++i) {
newptr[i] = ((const short *) (src->Numbers))[i];
@@ -672,7 +677,7 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
}
}
} else {
- dst->ext_Names = 0;
+ dst->ext_Names = NULL;
}
#endif
(void) new_table_size;