ncurses 6.0 - patch 20160910
[ncurses.git] / test / demo_terminfo.c
index c6abc028b949ad886d12f494379c9426e1dcf832..c1fffc7048f057277dd0295c8f5fa63dfffc1f8e 100644 (file)
@@ -29,7 +29,7 @@
 /*
  * Author: Thomas E. Dickey
  *
- * $Id: demo_terminfo.c,v 1.41 2016/06/04 23:19:32 tom Exp $
+ * $Id: demo_terminfo.c,v 1.44 2016/09/10 21:22:49 tom Exp $
  *
  * A simple demo of the terminfo interface.
  */
@@ -95,8 +95,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;
 }
 
@@ -312,6 +313,12 @@ abcdefghijklmnopqrstuvwxyz_";
     del_curterm(cur_term);
 }
 
+#if USE_CODE_LISTS
+#define fullname(type,n) f_opt ? type##fnames[n] : cap
+#else
+#define fullname(type,n) cap
+#endif
+
 static void
 demo_terminfo(char *name)
 {
@@ -330,7 +337,7 @@ demo_terminfo(char *name)
            cap = my_boolcodes[n];
            if (cap == 0)
                break;
-           dumpit(cap, f_opt ? boolfnames[n] : cap);
+           dumpit(cap, fullname(bool, n));
        }
     }
 
@@ -339,7 +346,7 @@ demo_terminfo(char *name)
            cap = my_numcodes[n];
            if (cap == 0)
                break;
-           dumpit(cap, f_opt ? numfnames[n] : cap);
+           dumpit(cap, fullname(num, n));
        }
     }
 
@@ -348,7 +355,7 @@ demo_terminfo(char *name)
            cap = my_strcodes[n];
            if (cap == 0)
                break;
-           dumpit(cap, f_opt ? strfnames[n] : cap);
+           dumpit(cap, fullname(str, n));
        }
     }
 #ifdef NCURSES_VERSION
@@ -390,9 +397,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);
                }
@@ -727,7 +736,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;
            }
        }