Backport of:

From f80e543c6dee5ecfe54c58d351fe418ce5f1959b Mon Sep 17 00:00:00 2001
From: "Thomas E. Dickey" <dickey@invisible-island.net>
Date: Wed, 10 Feb 2021 01:14:51 +0000
Subject: [PATCH] snapshot of project "xterm", label xterm-365e

---
 MANIFEST       |  2 +-
 button.c       | 24 +++++++++++++++---------
 charproc.c     |  6 +++---
 main.c         |  4 ++--
 misc.c         |  6 +++---
 xterm.log.html |  6 +++++-
 6 files changed, 29 insertions(+), 19 deletions(-)

--- a/button.c
+++ b/button.c
@@ -405,7 +405,7 @@ xtermButtonInit(XtermWidget xw)
 	Bool want_button = False;
 	Bool have_shift = False;
 
-	TRACE(("xtermButtonInit length %ld\n", strlen(result)));
+	TRACE(("xtermButtonInit length %ld\n", (long) strlen(result)));
 	xw->keyboard.print_translations = data;
 	while ((next = scanTrans(data, &state, &state2, &first, &last)) != 0) {
 	    unsigned len = (last - first);
@@ -4281,14 +4281,20 @@ SaltTextAway(XtermWidget xw,
      * the estimate is too-far off.
      */
     if ((have * 2) < (size_t) need) {
+	Char *next;
 	scp->data_limit = have + 1;
-	line = realloc(line, scp->data_limit);
+	next = realloc(line, scp->data_limit);
+	if (next == NULL) {
+	    free(line);
+	    scp->data_length = 0;
+	    scp->data_limit = 0;
+	}
+	scp->data_buffer = next;
     }
+    scp->data_length = have;
 
     TRACE(("Salted TEXT:%u:%s\n", (unsigned) have,
-	   visibleChars(line, (unsigned) have)));
-
-    scp->data_length = have;
+	   visibleChars(scp->data_buffer, (unsigned) have)));
 }
 
 #if OPT_PASTE64
@@ -4769,7 +4775,7 @@ _OwnSelection(XtermWidget xw,
 	    scp = &(screen->selected_cells[CutBufferToCode(cutbuffer)]);
 	    if (scp->data_length > limit) {
 		TRACE(("selection too big (%lu bytes), not storing in CUT_BUFFER%d\n",
-		       scp->data_length, cutbuffer));
+		       (unsigned long) scp->data_length, cutbuffer));
 		xtermWarning("selection too big (%lu bytes), not storing in CUT_BUFFER%d\n",
 			     (unsigned long) scp->data_length, cutbuffer);
 	    } else {
@@ -4825,8 +4831,8 @@ _OwnSelection(XtermWidget xw,
 				   SelectionDone);
 	    }
 	}
-	TRACE(("... _OwnSelection used length %ld value %s\n",
-	       scp->data_length,
+	TRACE(("... _OwnSelection used length %lu value %s\n",
+	       (unsigned long) scp->data_length,
 	       visibleChars(scp->data_buffer,
 			    (unsigned) scp->data_length)));
     }
