]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/alloc_entry.c
ncurses 6.2 - patch 20210508
[ncurses.git] / ncurses / tinfo / alloc_entry.c
index 13bb3a020161498f00c3e6dd2b0765cbc01724b8..de2801243c582e6366feb44c762ea9f36a509dbe 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2013,2017 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 1998-2013,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -47,7 +48,7 @@
 
 #include <tic.h>
 
 
 #include <tic.h>
 
-MODULE_ID("$Id: alloc_entry.c,v 1.59 2017/04/09 23:33:51 tom Exp $")
+MODULE_ID("$Id: alloc_entry.c,v 1.65 2021/05/04 23:15:34 tom Exp $")
 
 #define ABSENT_OFFSET    -1
 #define CANCELLED_OFFSET -2
 
 #define ABSENT_OFFSET    -1
 #define CANCELLED_OFFSET -2
@@ -96,7 +97,11 @@ _nc_save_str(const char *const string)
 {
     char *result = 0;
     size_t old_next_free = next_free;
 {
     char *result = 0;
     size_t old_next_free = next_free;
-    size_t len = strlen(string) + 1;
+    size_t len;
+
+    if (!VALID_STRING(string))
+       return _nc_save_str("");
+    len = strlen(string) + 1;
 
     if (len == 1 && next_free != 0) {
        /*
 
     if (len == 1 && next_free != 0) {
        /*
@@ -223,13 +228,21 @@ _nc_merge_entry(ENTRY * const target, ENTRY * const source)
 {
     TERMTYPE2 *to = &(target->tterm);
     TERMTYPE2 *from = &(source->tterm);
 {
     TERMTYPE2 *to = &(target->tterm);
     TERMTYPE2 *from = &(source->tterm);
+#if NCURSES_XNAMES
+    TERMTYPE2 copy;
+#endif
     unsigned i;
 
     unsigned i;
 
+    if (source == 0 || from == 0 || target == 0 || to == 0)
+       return;
+
 #if NCURSES_XNAMES
 #if NCURSES_XNAMES
+    _nc_copy_termtype2(&copy, from);
+    from = &copy;
     _nc_align_termtype(to, from);
 #endif
     for_each_boolean(i, from) {
     _nc_align_termtype(to, from);
 #endif
     for_each_boolean(i, from) {
-       if (to->Booleans[i] != (char) CANCELLED_BOOLEAN) {
+       if (to->Booleans[i] != (NCURSES_SBOOL) CANCELLED_BOOLEAN) {
            int mergebool = from->Booleans[i];
 
            if (mergebool == CANCELLED_BOOLEAN)
            int mergebool = from->Booleans[i];
 
            if (mergebool == CANCELLED_BOOLEAN)
@@ -265,6 +278,16 @@ _nc_merge_entry(ENTRY * const target, ENTRY * const source)
                to->Strings[i] = mergestring;
        }
     }
                to->Strings[i] = mergestring;
        }
     }
+#if NCURSES_XNAMES
+    /* Discard the data allocated in _nc_copy_termtype2, but do not use
+     * _nc_free_termtype2 because that frees the string-table (which is
+     * not allocated by _nc_copy_termtype2).
+     */
+    free(copy.Booleans);
+    free(copy.Numbers);
+    free(copy.Strings);
+    free(copy.ext_Names);
+#endif
 }
 
 #if NO_LEAKS
 }
 
 #if NO_LEAKS