]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/worm.c
ncurses 5.9 - patch 20130209
[ncurses.git] / test / worm.c
index 98f099cb9cb6e94deb2af7b602705a4e9631dc69..0d2209915c96654b7f0706291b098556227ff9e0 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2012 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -61,7 +61,7 @@ Options:
   traces will be dumped.  The program stops and waits for one character of
   input at the beginning and end of the interval.
 
   traces will be dumped.  The program stops and waits for one character of
   input at the beginning and end of the interval.
 
-  $Id: worm.c,v 1.60 2010/11/13 20:21:21 tom Exp $
+  $Id: worm.c,v 1.63 2013/01/13 01:00:11 tom Exp $
 */
 
 #include <test.priv.h>
 */
 
 #include <test.priv.h>
@@ -201,6 +201,14 @@ static const struct options {
 };
 /* *INDENT-ON* */
 
 };
 /* *INDENT-ON* */
 
+static void
+failed(const char *s)
+{
+    perror(s);
+    endwin();
+    ExitProgram(EXIT_FAILURE);
+}
+
 static void
 cleanup(void)
 {
 static void
 cleanup(void)
 {
@@ -391,6 +399,8 @@ update_refs(WINDOW *win)
     if (last_x != COLS - 1) {
        for (y = 0; y <= last_y; y++) {
            refs[y] = typeRealloc(int, (size_t) COLS, refs[y]);
     if (last_x != COLS - 1) {
        for (y = 0; y <= last_y; y++) {
            refs[y] = typeRealloc(int, (size_t) COLS, refs[y]);
+           if (!refs[y])
+               failed("update_refs");
            for (x = last_x + 1; x < COLS; x++)
                refs[y][x] = 0;
        }
            for (x = last_x + 1; x < COLS; x++)
                refs[y][x] = 0;
        }
@@ -402,6 +412,8 @@ update_refs(WINDOW *win)
        refs = typeRealloc(int *, (size_t) LINES, refs);
        for (y = last_y + 1; y < LINES; y++) {
            refs[y] = typeMalloc(int, (size_t) COLS);
        refs = typeRealloc(int *, (size_t) LINES, refs);
        for (y = last_y + 1; y < LINES; y++) {
            refs[y] = typeMalloc(int, (size_t) COLS);
+           if (!refs[y])
+               failed("update_refs");
            for (x = 0; x < COLS; x++)
                refs[y][x] = 0;
        }
            for (x = 0; x < COLS; x++)
                refs[y][x] = 0;
        }
@@ -419,6 +431,7 @@ main(int argc, char *argv[])
     struct worm *w;
     int *ip;
     bool done = FALSE;
     struct worm *w;
     int *ip;
     bool done = FALSE;
+    int max_refs;
 
     setlocale(LC_ALL, "");
 
 
     setlocale(LC_ALL, "");
 
@@ -489,7 +502,7 @@ main(int argc, char *argv[])
 
 #define SET_COLOR(num, fg) \
            init_pair(num+1, (short) fg, (short) bg); \
 
 #define SET_COLOR(num, fg) \
            init_pair(num+1, (short) fg, (short) bg); \
-           flavor[num] |= COLOR_PAIR(num+1) | A_BOLD
+           flavor[num] |= (chtype) COLOR_PAIR(num+1) | A_BOLD
 
        SET_COLOR(0, COLOR_GREEN);
        SET_COLOR(1, COLOR_RED);
 
        SET_COLOR(0, COLOR_GREEN);
        SET_COLOR(1, COLOR_RED);
@@ -501,8 +514,9 @@ main(int argc, char *argv[])
     }
 #endif /* A_COLOR */
 
     }
 #endif /* A_COLOR */
 
-    refs = typeMalloc(int *, (size_t) LINES);
-    for (y = 0; y < LINES; y++) {
+    max_refs = LINES;
+    refs = typeMalloc(int *, (size_t) max_refs);
+    for (y = 0; y < max_refs; y++) {
        refs[y] = typeMalloc(int, (size_t) COLS);
        for (x = 0; x < COLS; x++) {
            refs[y][x] = 0;
        refs[y] = typeMalloc(int, (size_t) COLS);
        for (x = 0; x < COLS; x++) {
            refs[y][x] = 0;
@@ -596,7 +610,7 @@ main(int argc, char *argv[])
     Trace(("Cleanup"));
     cleanup();
 #ifdef NO_LEAKS
     Trace(("Cleanup"));
     cleanup();
 #ifdef NO_LEAKS
-    for (y = 0; y < LINES; y++) {
+    for (y = 0; y < max_refs; y++) {
        free(refs[y]);
     }
     free(refs);
        free(refs[y]);
     }
     free(refs);