X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=ncurses%2Ftinfo%2Falloc_ttype.c;h=ff32770d032db1b7b103eaf3ee6f70f1d8e3e737;hb=d1a029866f6d84087781eaa81de19949d8533426;hp=9f866323058ee373f6b0f6368a9d952a31dff2e8;hpb=f8401f5e8669eadd551fde12da7de661c18fa4f2;p=ncurses.git diff --git a/ncurses/tinfo/alloc_ttype.c b/ncurses/tinfo/alloc_ttype.c index 9f866323..ff32770d 100644 --- a/ncurses/tinfo/alloc_ttype.c +++ b/ncurses/tinfo/alloc_ttype.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2021,2022 Thomas E. Dickey * + * Copyright 2018-2022,2023 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 -MODULE_ID("$Id: alloc_ttype.c,v 1.40 2022/05/08 00:11:44 tom Exp $") +MODULE_ID("$Id: alloc_ttype.c,v 1.49 2023/05/27 20:13:10 tom Exp $") #if NCURSES_XNAMES /* @@ -378,8 +378,8 @@ adjust_cancels(TERMTYPE2 *to, TERMTYPE2 *from) int j, k; DEBUG(3, (T_CALLED("adjust_cancels(%s), from(%s)"), - to ? NonNull(to->term_names) : "?", - from ? NonNull(from->term_names) : "?")); + NonNull(to->term_names), + NonNull(from->term_names))); for (j = first; j < last;) { char *name = to->ext_Names[j]; int j_str = to->num_Strings - first - to->ext_Strings; @@ -552,12 +552,14 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode) new_table = NULL; for (pass = 0; pass < 2; ++pass) { size_t str_size = 0; - if (pass) { - dst->term_names = new_table + str_size; - strcpy(dst->term_names + str_size, src->term_names); + if (src->term_names != NULL) { + if (pass) { + dst->term_names = new_table + str_size; + strcpy(dst->term_names + str_size, src->term_names); + } + str_size += strlen(src->term_names) + 1; } - str_size += strlen(src->term_names) + 1; - for (i = 0; i < NUM_STRINGS(dst); ++i) { + for_each_string(i, src) { if (VALID_STRING(src->Strings[i])) { if (pass) { strcpy(new_table + str_size, src->Strings[i]); @@ -570,7 +572,8 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode) dst->str_table = new_table; } else { ++str_size; - new_table = malloc(str_size); + if ((new_table = malloc(str_size)) == NULL) + _nc_err_abort(MSG_NO_MEMORY); } } @@ -625,6 +628,19 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode) new_table = NULL; for (pass = 0; pass < 2; ++pass) { size_t str_size = 0; + char *raw_data = src->ext_str_table; + if (raw_data != NULL) { + for (i = 0; i < src->ext_Strings; ++i) { + size_t skip = strlen(raw_data) + 1; + if (skip != 1) { + if (pass) { + strcpy(new_table + str_size, raw_data); + } + str_size += skip; + raw_data += skip; + } + } + } for (i = 0; i < NUM_EXT_NAMES(dst); ++i) { if (VALID_STRING(src->ext_Names[i])) { if (pass) { @@ -638,7 +654,8 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode) dst->ext_str_table = new_table; } else { ++str_size; - new_table = malloc(str_size); + if ((new_table = calloc(str_size, 1)) == NULL) + _nc_err_abort(MSG_NO_MEMORY); } } } else { @@ -648,9 +665,6 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode) DEBUG(2, (T_RETURN(""))); } -/* - * This entrypoint is used by tack 1.07 - */ NCURSES_EXPORT(void) _nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src) {