]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/alloc_ttype.c
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / tinfo / alloc_ttype.c
index ff32770d032db1b7b103eaf3ee6f70f1d8e3e737..304c1b62f4e691e39675f021bb8d167256c101ea 100644 (file)
@@ -43,7 +43,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: alloc_ttype.c,v 1.49 2023/05/27 20:13:10 tom Exp $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.51 2023/09/09 23:15:53 tom Exp $")
 
 #if NCURSES_XNAMES
 /*
@@ -530,6 +530,7 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
     unsigned i;
     int pass;
     char *new_table;
+    size_t new_table_size;
 #if NCURSES_EXT_NUMBERS
     short *oldptr = 0;
     int *newptr = 0;
@@ -550,19 +551,24 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
           NUM_STRINGS(dst) * sizeof(dst->Strings[0]));
 
     new_table = NULL;
+    new_table_size = 0;
     for (pass = 0; pass < 2; ++pass) {
        size_t str_size = 0;
        if (src->term_names != NULL) {
            if (pass) {
                dst->term_names = new_table + str_size;
-               strcpy(dst->term_names + str_size, src->term_names);
+               _nc_STRCPY(dst->term_names + str_size,
+                          src->term_names,
+                          new_table_size - str_size);
            }
            str_size += strlen(src->term_names) + 1;
        }
        for_each_string(i, src) {
            if (VALID_STRING(src->Strings[i])) {
                if (pass) {
-                   strcpy(new_table + str_size, src->Strings[i]);
+                   _nc_STRCPY(new_table + str_size,
+                              src->Strings[i],
+                              new_table_size - str_size);
                    dst->Strings[i] = new_table + str_size;
                }
                str_size += strlen(src->Strings[i]) + 1;
@@ -574,6 +580,7 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
            ++str_size;
            if ((new_table = malloc(str_size)) == NULL)
                _nc_err_abort(MSG_NO_MEMORY);
+           new_table_size = str_size;
        }
     }
 
@@ -626,6 +633,7 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
        memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *));
 
        new_table = NULL;
+       new_table_size = 0;
        for (pass = 0; pass < 2; ++pass) {
            size_t str_size = 0;
            char *raw_data = src->ext_str_table;
@@ -634,7 +642,9 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
                    size_t skip = strlen(raw_data) + 1;
                    if (skip != 1) {
                        if (pass) {
-                           strcpy(new_table + str_size, raw_data);
+                           _nc_STRCPY(new_table + str_size,
+                                      raw_data,
+                                      new_table_size - str_size);
                        }
                        str_size += skip;
                        raw_data += skip;
@@ -644,7 +654,9 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
            for (i = 0; i < NUM_EXT_NAMES(dst); ++i) {
                if (VALID_STRING(src->ext_Names[i])) {
                    if (pass) {
-                       strcpy(new_table + str_size, src->ext_Names[i]);
+                       _nc_STRCPY(new_table + str_size,
+                                  src->ext_Names[i],
+                                  new_table_size - str_size);
                        dst->ext_Names[i] = new_table + str_size;
                    }
                    str_size += strlen(src->ext_Names[i]) + 1;
@@ -656,12 +668,14 @@ copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
                ++str_size;
                if ((new_table = calloc(str_size, 1)) == NULL)
                    _nc_err_abort(MSG_NO_MEMORY);
+               new_table_size = str_size;
            }
        }
     } else {
        dst->ext_Names = 0;
     }
 #endif
+    (void) new_table_size;
     DEBUG(2, (T_RETURN("")));
 }