]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_overlay.c
ncurses 5.9 - patch 20141101
[ncurses.git] / ncurses / base / lib_overlay.c
index bfb817bc310833782222362024d067de4fa917b4..a206248a1e74ee3afc18d14508d43bbee49d53d4 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2013 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            *
@@ -40,7 +40,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_overlay.c,v 1.29 2009/10/24 23:21:31 tom Exp $")
+MODULE_ID("$Id: lib_overlay.c,v 1.31 2013/04/06 23:47:13 tom Exp $")
 
 static int
 overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
@@ -151,7 +151,10 @@ copywin(const WINDOW *src, WINDOW *dst,
        dminrow, dmincol,
        dmaxrow, dmaxcol, over));
 
-    if (src && dst) {
+    if (src != 0
+       && dst != 0
+       && dmaxrow >= dminrow
+       && dmaxcol >= dmincol) {
        _nc_lock_global(curses);
 
        bk = AttrOf(dst->_nc_bkgd);
@@ -160,6 +163,7 @@ copywin(const WINDOW *src, WINDOW *dst,
        /* make sure rectangle exists in source */
        if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) &&
            (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) {
+           bool copied = FALSE;
 
            T(("rectangle exists in source"));
 
@@ -172,10 +176,18 @@ copywin(const WINDOW *src, WINDOW *dst,
                     dy <= dmaxrow;
                     sy++, dy++) {
 
+                   if (dy < 0 || sy < 0)
+                       continue;
+
                    touched = FALSE;
                    for (dx = dmincol, sx = smincol;
                         dx <= dmaxcol;
                         sx++, dx++) {
+
+                       if (dx < 0 || sx < 0)
+                           continue;
+                       copied = TRUE;
+
                        if (over) {
                            if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
                                (!CharEq(dst->_line[dy].text[dx],
@@ -201,7 +213,8 @@ copywin(const WINDOW *src, WINDOW *dst,
                    }
                }
                T(("finished copywin"));
-               rc = OK;
+               if (copied)
+                   rc = OK;
            }
        }
        _nc_unlock_global(curses);