Update to ncurses-6.0

Change-Id: I98ab2ea8a5e13cca9f8b7cf6277b9b14a4da4299
diff --git a/ncurses/base/lib_overlay.c b/ncurses/base/lib_overlay.c
index 669e8e7..a206248 100644
--- a/ncurses/base/lib_overlay.c
+++ b/ncurses/base/lib_overlay.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,2008 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.27 2008/06/07 23:30:34 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)
@@ -52,7 +52,7 @@
     int dminrow, dmincol;
     int dmaxrow, dmaxcol;
 
-    T((T_CALLED("overlap(%p,%p,%d)"), src, dst, flag));
+    T((T_CALLED("overlap(%p,%p,%d)"), (const void *) src, (void *) dst, flag));
 
     if (src != 0 && dst != 0) {
 	_nc_lock_global(curses);
@@ -110,7 +110,7 @@
 NCURSES_EXPORT(int)
 overlay(const WINDOW *win1, WINDOW *win2)
 {
-    T((T_CALLED("overlay(%p,%p)"), win1, win2));
+    T((T_CALLED("overlay(%p,%p)"), (const void *) win1, (void *) win2));
     returnCode(overlap(win1, win2, TRUE));
 }
 
@@ -127,7 +127,7 @@
 NCURSES_EXPORT(int)
 overwrite(const WINDOW *win1, WINDOW *win2)
 {
-    T((T_CALLED("overwrite(%p,%p)"), win1, win2));
+    T((T_CALLED("overwrite(%p,%p)"), (const void *) win1, (void *) win2));
     returnCode(overlap(win1, win2, FALSE));
 }
 
@@ -145,9 +145,16 @@
     attr_t mask;
 
     T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
-       src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
+       (const void *) src,
+       (void *) dst,
+       sminrow, smincol,
+       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);
@@ -156,6 +163,7 @@
 	/* 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"));
 
@@ -168,10 +176,18 @@
 		     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],
@@ -197,7 +213,8 @@
 		    }
 		}
 		T(("finished copywin"));
-		rc = OK;
+		if (copied)
+		    rc = OK;
 	    }
 	}
 	_nc_unlock_global(curses);