]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_menus.c
ncurses 6.0 - patch 20170603
[ncurses.git] / test / demo_menus.c
index 7fe0ea37394dab003ead0e3b3e9eb243f83c8a71..00fe5b4321c39bc7466bd4a5ea22b74cf0f7b9fc 100644 (file)
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_menus.c,v 1.59 2016/03/27 00:02:01 tom Exp $
+ * $Id: demo_menus.c,v 1.62 2016/09/10 23:30:33 tom Exp $
  *
  * Demonstrate a variety of functions from the menu library.
  * Thomas Dickey - 2005/4/9
@@ -113,6 +113,15 @@ static WINDOW *status;
 static bool loaded_file = FALSE;
 
 static char empty[1];
+static void failed(const char *s) GCC_NORETURN;
+
+static void
+failed(const char *s)
+{
+    perror(s);
+    endwin();
+    ExitProgram(EXIT_FAILURE);
+}
 
 /* Common function to allow ^T to toggle trace-mode in the middle of a test
  * so that trace-files can be made smaller.
@@ -544,27 +553,31 @@ static char *
 tracetrace(unsigned tlevel)
 {
     static char *buf;
+    static size_t need = 12;
     int n;
 
     if (buf == 0) {
-       size_t need = 12;
        for (n = 0; t_tbl[n].name != 0; n++)
            need += strlen(t_tbl[n].name) + 2;
        buf = typeMalloc(char, need);
+       if (!buf)
+           failed("tracetrace");
     }
-    sprintf(buf, "0x%02x = {", tlevel);
+    _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
     if (tlevel == 0) {
-       sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
+       _nc_STRCAT(buf, t_tbl[0].name, need);
+       _nc_STRCAT(buf, ", ", need);
     } else {
        for (n = 1; t_tbl[n].name != 0; n++)
            if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
-               strcat(buf, t_tbl[n].name);
-               strcat(buf, ", ");
+               _nc_STRCAT(buf, t_tbl[n].name, need);
+               _nc_STRCAT(buf, ", ", need);
            }
     }
     if (buf[strlen(buf) - 2] == ',')
        buf[strlen(buf) - 2] = '\0';
-    return (strcat(buf, "}"));
+    _nc_STRCAT(buf, "}", need);
+    return buf;
 }
 
 /* fake a dynamically reconfigurable menu using the 0th entry to deselect