libncurses: Import https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz changes

Change-Id: I3433d30ca01359fd2e3623ede96b531f0b39cbfa
Signed-off-by: micky387 <mickaelsaibi@free.fr>
diff --git a/ncurses/tty/hashmap.c b/ncurses/tty/hashmap.c
index 8c0fdfd..e50b638 100644
--- a/ncurses/tty/hashmap.c
+++ b/ncurses/tty/hashmap.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
+ * Copyright 2019-2020,2023 Thomas E. Dickey                                *
+ * Copyright 1998-2015,2016 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            *
@@ -73,7 +74,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: hashmap.c,v 1.65 2015/07/25 20:13:56 tom Exp $")
+MODULE_ID("$Id: hashmap.c,v 1.71 2023/09/16 16:28:53 tom Exp $")
 
 #ifdef HASHDEBUG
 
@@ -87,7 +88,7 @@
 # undef screen_lines
 # define screen_lines(sp) MAXLINES
 # define TEXTWIDTH(sp)	1
-int oldnums[MAXLINES], reallines[MAXLINES];
+static int oldnums[MAXLINES], reallines[MAXLINES];
 static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH(sp)];
 static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH(sp)];
 # define OLDNUM(sp,n)	oldnums[n]
@@ -119,7 +120,7 @@
 static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
 
 static NCURSES_INLINE unsigned long
-hash(SCREEN *sp, NCURSES_CH_T * text)
+hash(SCREEN *sp, NCURSES_CH_T *text)
 {
     int i;
     NCURSES_CH_T ch;
@@ -135,7 +136,7 @@
 
 /* approximate update cost */
 static int
-update_cost(SCREEN *sp, NCURSES_CH_T * from, NCURSES_CH_T * to)
+update_cost(SCREEN *sp, NCURSES_CH_T *from, NCURSES_CH_T *to)
 {
     int cost = 0;
     int i;
@@ -149,7 +150,7 @@
 }
 
 static int
-update_cost_from_blank(SCREEN *sp, NCURSES_CH_T * to)
+update_cost_from_blank(SCREEN *sp, NCURSES_CH_T *to)
 {
     int cost = 0;
     int i;
@@ -198,9 +199,8 @@
 static void
 grow_hunks(SCREEN *sp)
 {
-    int start, end, shift;
-    int back_limit, forward_limit;	/* limits for cells to fill */
-    int back_ref_limit, forward_ref_limit;	/* limits for refrences */
+    int back_limit;		/* limits for cells to fill */
+    int back_ref_limit;		/* limit for references */
     int i;
     int next_hunk;
 
@@ -215,8 +215,11 @@
     while (i < screen_lines(sp) && OLDNUM(sp, i) == _NEWINDEX)
 	i++;
     for (; i < screen_lines(sp); i = next_hunk) {
-	start = i;
-	shift = OLDNUM(sp, i) - i;
+	int forward_limit;
+	int forward_ref_limit;
+	int end;
+	int start = i;
+	int shift = OLDNUM(sp, i) - i;
 
 	/* get forward limit */
 	i = start + 1;
@@ -285,7 +288,6 @@
 {
     HASHMAP *hsp;
     register int i;
-    int start, shift, size;
 
     if (screen_lines(SP_PARM) > lines_alloc(SP_PARM)) {
 	if (hashtab(SP_PARM))
@@ -316,8 +318,11 @@
 	if (newhash(SP_PARM) == 0)
 	    newhash(SP_PARM) = typeCalloc(unsigned long,
 					    (size_t) screen_lines(SP_PARM));
-	if (!oldhash(SP_PARM) || !newhash(SP_PARM))
+	if (!oldhash(SP_PARM) || !newhash(SP_PARM)) {
+	    FreeAndNull(oldhash(SP_PARM));
+	    FreeAndNull(newhash(SP_PARM));
 	    return;		/* malloc failure */
+	}
 	for (i = 0; i < screen_lines(SP_PARM); i++) {
 	    newhash(SP_PARM)[i] = hash(SP_PARM, NEWTEXT(SP_PARM, i));
 	    oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
@@ -387,6 +392,8 @@
      * more than carry.
      */
     for (i = 0; i < screen_lines(SP_PARM);) {
+	int start, shift, size;
+
 	while (i < screen_lines(SP_PARM) && OLDNUM(SP_PARM, i) == _NEWINDEX)
 	    i++;
 	if (i >= screen_lines(SP_PARM))
@@ -399,7 +406,7 @@
 	       && OLDNUM(SP_PARM, i) - i == shift)
 	    i++;
 	size = i - start;
-	if (size < 3 || size + min(size / 8, 2) < abs(shift)) {
+	if (size < 3 || size + Min(size / 8, 2) < abs(shift)) {
 	    while (start < i) {
 		OLDNUM(SP_PARM, start) = _NEWINDEX;
 		start++;
@@ -580,11 +587,7 @@
 	    break;
 	}
     }
-#if NO_LEAKS
-    _nc_free_and_exit(EXIT_SUCCESS);
-#else
-    return EXIT_SUCCESS;
-#endif
+    exit_curses(EXIT_SUCCESS);
 }
 
 #endif /* HASHDEBUG */