]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/filter.c
ncurses 6.0 - patch 20170902
[ncurses.git] / test / filter.c
index 89096ba370ff3c0082b89af0d2ddd34474faaa48..926ec6b8dcae143c6e864dfbaa7ba4a4a182a26e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2014,2016 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-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 1998
  *
- * $Id: filter.c,v 1.26 2016/08/20 20:38:56 tom Exp $
+ * $Id: filter.c,v 1.29 2017/06/17 18:16:39 tom Exp $
  *
  * An example of the 'filter()' function in ncurses, this program prompts
  * for commands and executes them (like a command shell).  It illustrates
@@ -68,10 +68,10 @@ show_prompt(int underline, bool clocked)
            int skip, y, x;
            int margin;
 
-           sprintf(buffer, "%02d:%02d:%02d",
-                   my->tm_hour,
-                   my->tm_min,
-                   my->tm_sec);
+           _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%02d:%02d:%02d",
+                       my->tm_hour,
+                       my->tm_min,
+                       my->tm_sec);
 
            if (limit > 9) {
                skip = 0;
@@ -242,11 +242,11 @@ new_command(char *buffer, int length, int underline, bool clocked, bool polled)
         */
 #ifdef KEY_EVENT
        if (code == KEY_EVENT)
-           strcpy(buffer, "# event!");
+           _nc_STRCPY(buffer, "# event!", length);
 #endif
 #ifdef KEY_RESIZE
        if (code == KEY_RESIZE) {
-           strcpy(buffer, "# resize!");
+           _nc_STRCPY(buffer, "# resize!", length);
            getch();
        }
 #endif
@@ -359,7 +359,10 @@ main(int argc, char *argv[])
     if (i_option) {
        initscr();
     } else {
-       (void) newterm((char *) 0, stdout, stdin);
+       if (newterm((char *) 0, stdout, stdin) == 0) {
+           fprintf(stderr, "cannot initialize terminal\n");
+           ExitProgram(EXIT_FAILURE);
+       }
     }
 #ifdef NCURSES_VERSION
     if (a_option) {