]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_terminfo.c
ncurses 6.1 - patch 20180127
[ncurses.git] / test / demo_terminfo.c
index e2f771a98bbad7052bca76f127a43303941416a6..ab1c22c425cfeb6d4452d4ad49e42fd68447068e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2009-2015,2016 Free Software Foundation, Inc.              *
+ * Copyright (c) 2009-2016,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            *
@@ -29,7 +29,7 @@
 /*
  * Author: Thomas E. Dickey
  *
- * $Id: demo_terminfo.c,v 1.42 2016/06/18 23:57:33 tom Exp $
+ * $Id: demo_terminfo.c,v 1.48 2017/11/24 20:49:11 tom Exp $
  *
  * A simple demo of the terminfo interface.
  */
@@ -69,8 +69,10 @@ static bool f_opt = FALSE;
 static bool n_opt = FALSE;
 static bool q_opt = FALSE;
 static bool s_opt = FALSE;
+#ifdef NCURSES_VERSION
 static bool x_opt = FALSE;
 static bool y_opt = FALSE;
+#endif
 
 static char *d_opt;
 static char *e_opt;
@@ -95,8 +97,9 @@ static long total_s_values;
 static char *
 make_dbitem(char *p, char *q)
 {
-    char *result = malloc(strlen(e_opt) + 2 + (size_t) (p - q));
-    sprintf(result, "%s=%.*s", e_opt, (int) (p - q), q);
+    size_t need = strlen(e_opt) + 2 + (size_t) (p - q);
+    char *result = malloc(need);
+    _nc_SPRINTF(result, _nc_SLIMIT(need) "%s=%.*s", e_opt, (int) (p - q), q);
     return result;
 }
 
@@ -151,7 +154,7 @@ next_dbitem(void)
     return result;
 }
 
-#ifdef NO_LEAKS
+#if NO_LEAKS
 static void
 free_dblist(void)
 {
@@ -362,7 +365,7 @@ demo_terminfo(char *name)
        int mod;
        if (y_opt) {
 #if NCURSES_XNAMES
-           TERMTYPE *term = &(cur_term->type);
+           TERMTYPE *term = (TERMTYPE *) cur_term;
            if (term != 0
                && ((NUM_BOOLEANS(term) != BOOLCOUNT)
                    || (NUM_NUMBERS(term) != NUMCOUNT)
@@ -396,9 +399,11 @@ demo_terminfo(char *name)
                            !strcmp(xterm_keys[n], "kRIT")) {
                            continue;
                        }
-                       sprintf(temp, "%.*s", 8, xterm_keys[n]);
+                       _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+                                   "%.*s", 8, xterm_keys[n]);
                    } else {
-                       sprintf(temp, "%.*s%d", 8, xterm_keys[n], mod);
+                       _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+                                   "%.*s%d", 8, xterm_keys[n], mod);
                    }
                    dumpit(temp, NULL);
                }
@@ -733,7 +738,7 @@ copy_code_list(NCURSES_CONST char *const *list)
                length += chunk;
            } else {
                result[count] = unused;
-               strcpy(unused, list[count]);
+               _nc_STRCPY(unused, list[count], length);
                unused += chunk;
            }
        }
@@ -748,7 +753,18 @@ copy_code_list(NCURSES_CONST char *const *list)
 
     return result;
 }
+
+#if NO_LEAKS
+static void
+free_code_list(char **list)
+{
+    if (list) {
+       free(list[0]);
+       free(list);
+    }
+}
 #endif
+#endif /* USE_CODE_LISTS */
 
 static void
 usage(void)
@@ -901,17 +917,26 @@ main(int argc, char *argv[])
           PLURAL(total_n_values),
           PLURAL(total_s_values));
 
-#ifdef NO_LEAKS
+#if NO_LEAKS
     free_dblist();
-    if (my_blob != 0) {
-       free(my_blob);
-       free(my_boolcodes);
-       free(my_numcodes);
-       free(my_numvalues);
-       free(my_strcodes);
-       free(my_strvalues);
+    if (input_name != 0) {
+       if (my_blob != 0) {
+           free(my_blob);
+           free(my_boolcodes);
+           free(my_numcodes);
+           free(my_numvalues);
+           free(my_strcodes);
+           free(my_strvalues);
+       }
+    }
+#if USE_CODE_LISTS
+    else {
+       free_code_list(my_boolcodes);
+       free_code_list(my_numcodes);
+       free_code_list(my_strcodes);
     }
 #endif
+#endif /* NO_LEAKS */
 
     ExitProgram(EXIT_SUCCESS);
 }