]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_screen.c
ncurses 5.6 - patch 20080830
[ncurses.git] / ncurses / base / lib_screen.c
index 43f848d8a64df6e9683f0a962c1abd705754a1d8..4aa58ea2a19c9caa51f9eb29ff7b49361c457d0c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2007,2008 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            *
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
- *     and: Thomas E. Dickey 1996 on                                        *
+ *     and: Thomas E. Dickey                        1996 on                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_screen.c,v 1.28 2002/09/14 23:30:41 tom Exp $")
+MODULE_ID("$Id: lib_screen.c,v 1.31 2008/08/16 19:05:37 tom Exp $")
+
+#define MAX_SIZE 0x3fff                /* 16k is big enough for a window or pad */
 
 NCURSES_EXPORT(WINDOW *)
-getwin(FILE * filep)
+getwin(FILE *filep)
 {
     WINDOW tmp, *nwin;
     int n;
@@ -46,7 +48,11 @@ getwin(FILE * filep)
 
     clearerr(filep);
     (void) fread(&tmp, sizeof(WINDOW), 1, filep);
-    if (ferror(filep))
+    if (ferror(filep)
+       || tmp._maxy == 0
+       || tmp._maxy > MAX_SIZE
+       || tmp._maxx == 0
+       || tmp._maxx > MAX_SIZE)
        returnWin(0);
 
     if (tmp._flags & _ISPAD) {
@@ -70,7 +76,7 @@ getwin(FILE * filep)
        nwin->_yoffset = tmp._yoffset;
        nwin->_flags = tmp._flags & ~(_SUBWIN);
 
-       nwin->_attrs = tmp._attrs;
+       WINDOW_ATTRS(nwin) = WINDOW_ATTRS(&tmp);
        nwin->_nc_bkgd = tmp._nc_bkgd;
 
        nwin->_notimeout = tmp._notimeout;
@@ -107,7 +113,7 @@ getwin(FILE * filep)
 }
 
 NCURSES_EXPORT(int)
-putwin(WINDOW *win, FILE * filep)
+putwin(WINDOW *win, FILE *filep)
 {
     int code = ERR;
     int n;
@@ -115,7 +121,7 @@ putwin(WINDOW *win, FILE * filep)
     T((T_CALLED("putwin(%p,%p)"), win, filep));
 
     if (win != 0) {
-       size_t len = (win->_maxx + 1);
+       size_t len = (size_t) (win->_maxx + 1);
 
        clearerr(filep);
        if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
@@ -146,7 +152,10 @@ scr_restore(const char *file)
        returnCode(ERR);
     } else {
        delwin(newscr);
-       SP->_newscr = newscr = getwin(fp);
+       SP->_newscr = getwin(fp);
+#if !USE_REENTRANT
+       newscr = SP->_newscr;
+#endif
        (void) fclose(fp);
        returnCode(OK);
     }
@@ -184,7 +193,10 @@ scr_init(const char *file)
        returnCode(ERR);
     } else {
        delwin(curscr);
-       SP->_curscr = curscr = getwin(fp);
+       SP->_curscr = getwin(fp);
+#if !USE_REENTRANT
+       curscr = SP->_curscr;
+#endif
        (void) fclose(fp);
        returnCode(OK);
     }
@@ -199,7 +211,10 @@ scr_set(const char *file)
        returnCode(ERR);
     } else {
        delwin(newscr);
-       SP->_newscr = newscr = dupwin(curscr);
+       SP->_newscr = dupwin(curscr);
+#if !USE_REENTRANT
+       newscr = SP->_newscr;
+#endif
        returnCode(OK);
     }
 }