]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_tparm.c
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / tinfo / lib_tparm.c
index 93af835049b1e25591c6d87d2582d4508b95ac4f..5666b27b7e098abace692da8f75276eb2b404543 100644 (file)
@@ -53,7 +53,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-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.153 2023/11/04 19:28:41 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;
     }
@@ -605,8 +607,8 @@ tparm_setup(TERMINAL *term, const char *string, TPARM_DATA *result)
     TPS(out_used) = 0;
     memset(result, 0, sizeof(*result));
 
-    if (string == NULL) {
-       TR(TRACE_CALLS, ("%s: format is null", TPS(tname)));
+    if (!VALID_STRING(string)) {
+       TR(TRACE_CALLS, ("%s: format is invalid", TPS(tname)));
        rc = ERR;
     } else {
 #if HAVE_TSEARCH
@@ -645,7 +647,7 @@ tparm_setup(TERMINAL *term, const char *string, TPARM_DATA *result)
                    result->num_parsed = NUM_PARM;
                if (result->num_popped > NUM_PARM)
                    result->num_popped = NUM_PARM;
-               result->num_actual = max(result->num_popped, result->num_parsed);
+               result->num_actual = Max(result->num_popped, result->num_parsed);
 
                for (n = 0; n < result->num_actual; ++n) {
                    if (result->p_is_s[n])
@@ -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("<null>")));
+       return NULL;
+    }
+
     while ((cp - string) < (int) len2) {
        if (*cp != '%') {
            save_char(tps, UChar(*cp));
@@ -1113,8 +1120,10 @@ check_string_caps(TPARM_DATA *data, const char *string)
            want_type = 2;      /* function key #1, transmit string #2 */
        else if (CHECK_CAP(plab_norm))
            want_type = 2;      /* label #1, show string #2 */
+#ifdef pkey_plab
        else if (CHECK_CAP(pkey_plab))
            want_type = 6;      /* function key #1, type string #2, show string #3 */
+#endif
 #if NCURSES_XNAMES
        else {
            char *check;