# ftp://ftp.invisible-island.net/xterm/patches/xterm-372.patch.gz
# patch by Thomas E. Dickey <dickey@invisible-island.net>
# created  Thu Mar 10 01:06:47 UTC 2022
# ------------------------------------------------------------------------------
# MANIFEST                 |    2 +-
# package/debian/changelog |    6 ++++++
# package/freebsd/Makefile |    4 ++--
# package/pkgsrc/Makefile  |    2 +-
# package/xterm.spec       |    4 ++--
# ptyx.h                   |   13 +++++++------
# screen.c                 |   37 +++++++++++++++++++++++++------------
# scrollback.c             |    8 ++++----
# util.c                   |    4 ++--
# version.h                |    6 +++---
# xterm.appdata.xml        |    2 +-
# xterm.h                  |    6 +++---
# xterm.log.html           |   14 +++++++++++++-
# 13 files changed, 70 insertions(+), 38 deletions(-)
# ------------------------------------------------------------------------------
Index: MANIFEST
--- xterm-371+/MANIFEST	2022-02-25 01:03:51.000000000 +0000
+++ xterm-372/MANIFEST	2022-03-04 21:39:26.000000000 +0000
@@ -1,4 +1,4 @@
-MANIFEST for xterm, version xterm-371
+MANIFEST for xterm, version xterm-372
 --------------------------------------------------------------------------------
 MANIFEST                        this file
 256colres.h                     resource-definitions for 256-color mode
Index: package/debian/changelog
--- xterm-371+/package/debian/changelog	2021-11-25 22:42:23.000000000 +0000
+++ xterm-372/package/debian/changelog	2022-03-04 21:39:26.000000000 +0000
@@ -1,3 +1,9 @@
+xterm-dev (372) unstable; urgency=low
+
+  * maintenance updates
+
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Fri, 04 Mar 2022 16:37:03 -0500
+
 xterm-dev (371) unstable; urgency=low
 
   * maintenance updates
Index: package/freebsd/Makefile
--- xterm-371+/package/freebsd/Makefile	2021-11-25 22:42:23.000000000 +0000
+++ xterm-372/package/freebsd/Makefile	2022-03-04 21:39:26.000000000 +0000
@@ -1,4 +1,4 @@
-# $XTermId: Makefile,v 1.92 2021/11/25 22:42:23 tom Exp $
+# $XTermId: Makefile,v 1.93 2022/03/04 21:39:26 tom Exp $
 # $FreeBSD: head/x11/xterm/Makefile 492827 2019-02-13 06:43:36Z ehaupt $
 
 # This is adapted from the FreeBSD port, installing as "xterm-dev" with
@@ -7,7 +7,7 @@
 # and "make makesum".
 
 PORTNAME=	xterm
-PORTVERSION=	371
+PORTVERSION=	372
 CATEGORIES=	x11
 MASTER_SITES=	ftp://ftp.invisible-island.net/xterm/:src1 \
 		https://invisible-mirror.net/archives/xterm/:src1
Index: package/pkgsrc/Makefile
--- xterm-371+/package/pkgsrc/Makefile	2021-11-25 22:42:23.000000000 +0000
+++ xterm-372/package/pkgsrc/Makefile	2022-03-04 21:39:26.000000000 +0000
@@ -1,6 +1,6 @@
 # $NetBSD: Makefile,v 1.117 2018/03/12 11:18:00 wiz Exp $
 
-DISTNAME=	xterm-371
+DISTNAME=	xterm-372
 PKGREVISION=	1
 CATEGORIES=	x11
 MASTER_SITES=	ftp://ftp.invisible-island.net/xterm/
Index: package/xterm.spec
--- xterm-371+/package/xterm.spec	2022-02-24 09:13:45.000000000 +0000
+++ xterm-372/package/xterm.spec	2022-03-04 21:39:26.000000000 +0000
@@ -1,11 +1,11 @@
-# $XTermId: xterm.spec,v 1.148 2022/02/24 09:13:45 tom Exp $
+# $XTermId: xterm.spec,v 1.149 2022/03/04 21:39:26 tom Exp $
 Summary: X terminal emulator (development version)
 %global my_middle xterm
 %global my_suffix -dev
 %global fullname %{my_middle}%{my_suffix}
 %global my_class XTermDev
 Name: %{fullname}
-Version: 371
+Version: 372
 Release: 1
 License: X11
 Group: User Interface/X
Index: ptyx.h
--- xterm-371+/ptyx.h	2022-02-14 01:08:54.000000000 +0000
+++ xterm-372/ptyx.h	2022-03-08 23:31:40.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: ptyx.h,v 1.1059 2022/02/14 01:08:54 tom Exp $ */
+/* $XTermId: ptyx.h,v 1.1060 2022/03/08 23:31:40 tom Exp $ */
 
 /*
  * Copyright 1999-2021,2022 by Thomas E. Dickey
@@ -3360,11 +3360,12 @@
 
 /*
  * terminal flags
- * There are actually two namespaces mixed together here.
- * One is the set of flags that can go in screen->visbuf attributes
- * and which must fit in a char (see OFF_ATTRS).
- * The other is the global setting stored in
- * term->flags and screen->save_modes.  This need only fit in an unsigned.
+ * There are actually two namespaces mixed together here:
+ * a) One is the set of flags that can go in screen->visbuf attributes and
+ *    which must fit in an IAttr (either a char or short, depending on whether
+ *    wide-attributes are used).
+ * b) The other is the global setting stored in term->flags and
+ *    screen->save_modes, which fits in an unsigned (IFlags).
  */
 
 #define AttrBIT(n)	xBIT(n)		/* text-attributes */
Index: screen.c
--- xterm-371+/screen.c	2022-02-18 21:15:37.000000000 +0000
+++ xterm-372/screen.c	2022-03-09 01:20:09.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: screen.c,v 1.620 2022/02/18 21:15:37 tom Exp $ */
+/* $XTermId: screen.c,v 1.623 2022/03/09 01:20:09 tom Exp $ */
 
 /*
  * Copyright 1999-2021,2022 by Thomas E. Dickey
@@ -176,7 +176,12 @@
  * Given a block of data, build index to it in the 'base' parameter.
  */
 void
-setupLineData(TScreen *screen, ScrnBuf base, Char *data, unsigned nrow, unsigned ncol)
+setupLineData(TScreen *screen,
+	      ScrnBuf base,
+	      Char *data,
+	      unsigned nrow,
+	      unsigned ncol,
+	      Bool bottom)
 {
     unsigned i;
     unsigned offset = 0;
@@ -194,7 +199,13 @@
 
     (void) screen;
     AlignValue(ncol);
-    AddStatusLineRows(nrow);
+
+    (void) bottom;
+#if OPT_STATUS_LINE
+    if (bottom) {
+	AddStatusLineRows(nrow);
+    }
+#endif
 
     skipNcolIAttr = (ncol * SizeofScrnPtr(attribs));
     skipNcolCharData = (ncol * SizeofScrnPtr(charData));
@@ -314,14 +325,16 @@
 }
 
 Char *
-allocScrnData(TScreen *screen, unsigned nrow, unsigned ncol)
+allocScrnData(TScreen *screen, unsigned nrow, unsigned ncol, Bool bottom)
 {
     Char *result = 0;
     size_t length;
 
     AlignValue(ncol);
-    AddStatusLineRows(nrow);
-    length = ((nrow + StatusLineRows) * sizeofScrnRow(screen, ncol));
+    if (bottom) {
+	AddStatusLineRows(nrow);
+    }
+    length = (nrow * sizeofScrnRow(screen, ncol));
     if (length == 0
 	|| (result = (Char *) calloc(length, sizeof(Char))) == 0)
 	  SysError(ERROR_SCALLOC2);
@@ -352,9 +365,9 @@
 
     if (nrow != 0) {
 	base = allocScrnHead(screen, nrow);
-	*addr = allocScrnData(screen, nrow, ncol);
+	*addr = allocScrnData(screen, nrow, ncol, True);
 
-	setupLineData(screen, base, *addr, nrow, ncol);
+	setupLineData(screen, base, *addr, nrow, ncol, True);
     }
 
     TRACE(("allocScrnBuf %dx%d ->%p\n", nrow, ncol, (void *) base));
@@ -471,7 +484,7 @@
      * Create the new buffer space and copy old buffer contents there, line by
      * line.
      */
-    newBufData = allocScrnData(screen, nrow, ncol);
+    newBufData = allocScrnData(screen, nrow, ncol, True);
     *sbufaddr = newBufData;
 
     minrows = (oldrow < nrow) ? oldrow : nrow;
@@ -482,7 +495,7 @@
 	}
     }
 
-    setupLineData(screen, newBufHead, *sbufaddr, nrow, ncol);
+    setupLineData(screen, newBufHead, *sbufaddr, nrow, ncol, True);
     extractScrnData(screen, newBufHead, oldBufHead, minrows, 0);
 
     /* Now free the old data */
@@ -535,8 +548,8 @@
 
     new_jump = scrnHeadSize(screen, 1);
     newBufHead = allocScrnHead(screen, nrow);
-    *sbufaddr = allocScrnData(screen, nrow, ncol);
-    setupLineData(screen, newBufHead, *sbufaddr, nrow, ncol);
+    *sbufaddr = allocScrnData(screen, nrow, ncol, True);
+    setupLineData(screen, newBufHead, *sbufaddr, nrow, ncol, True);
 
     screen->wide_chars = False;
 
Index: scrollback.c
--- xterm-371+/scrollback.c	2020-10-12 19:22:13.000000000 +0000
+++ xterm-372/scrollback.c	2022-03-09 00:38:51.000000000 +0000
@@ -1,7 +1,7 @@
-/* $XTermId: scrollback.c,v 1.21 2020/10/12 19:22:13 tom Exp $ */
+/* $XTermId: scrollback.c,v 1.23 2022/03/09 00:38:51 tom Exp $ */
 
 /*
- * Copyright 2009-2019,2020 by Thomas E. Dickey
+ * Copyright 2009-2020,2022 by Thomas E. Dickey
  *
  *                         All Rights Reserved
  *
@@ -95,10 +95,10 @@
 	}
 
 	/* allocate the new data */
-	block = allocScrnData(screen, 1, ncols);
+	block = allocScrnData(screen, 1, ncols, False);
 
 	/* record the new data in the index */
-	setupLineData(screen, where, (Char *) block, 1, ncols);
+	setupLineData(screen, where, (Char *) block, 1, ncols, False);
 
 	TRACE(("...storing new FIFO data in slot %d: %p->%p\n",
 	       which, (void *) where, block));
Index: util.c
--- xterm-371+/util.c	2022-02-22 09:30:14.000000000 +0000
+++ xterm-372/util.c	2022-03-08 00:48:22.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: util.c,v 1.897 2022/02/22 09:30:14 tom Exp $ */
+/* $XTermId: util.c,v 1.898 2022/03/08 00:48:22 tom Exp $ */
 
 /*
  * Copyright 1999-2021,2022 by Thomas E. Dickey
@@ -5012,7 +5012,7 @@
 
     assert((int) width > 0);
     assert((left + (int) width) <= screen->max_col + 1);
-    assert((int) height <= screen->max_row + 1);
+    assert((int) (height + top) <= screen->max_row + 1);
 
     if (VWindow(screen)) {
 	set_background(xw, xw->cur_background);
Index: version.h
--- xterm-371+/version.h	2022-02-24 09:07:28.000000000 +0000
+++ xterm-372/version.h	2022-03-10 00:58:00.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: version.h,v 1.520 2022/02/24 09:07:28 tom Exp $ */
+/* $XTermId: version.h,v 1.522 2022/03/10 00:58:00 tom Exp $ */
 
 /*
  * Copyright 1998-2021,2022 by Thomas E. Dickey
@@ -38,8 +38,8 @@
  * version of X to which this version of xterm has been built.  The resulting
  * number in parentheses is my patch number (Thomas E. Dickey).
  */
-#define XTERM_PATCH   371
-#define XTERM_DATE    2022-02-24
+#define XTERM_PATCH   372
+#define XTERM_DATE    2022-03-09
 
 #ifndef __vendorversion__
 #define __vendorversion__ "XTerm"
Index: xterm.appdata.xml
--- xterm-371+/xterm.appdata.xml	2022-02-24 09:07:12.000000000 +0000
+++ xterm-372/xterm.appdata.xml	2022-03-10 00:58:49.000000000 +0000
@@ -35,7 +35,7 @@
     <keyword>terminal</keyword>
   </keywords>
   <releases>
-    <release version="371" date="2022-02-24"/>
+    <release version="372" date="2022-03-09"/>
   </releases>
   <url type="homepage">https://invisible-island.net/xterm/</url>
   <update_contact>dickey@invisible-island.net</update_contact>
Index: xterm.h
--- xterm-371+/xterm.h	2022-02-11 09:18:53.000000000 +0000
+++ xterm-372/xterm.h	2022-03-09 00:39:01.000000000 +0000
@@ -1,4 +1,4 @@
-/* $XTermId: xterm.h,v 1.908 2022/02/11 09:18:53 tom Exp $ */
+/* $XTermId: xterm.h,v 1.910 2022/03/09 00:39:01 tom Exp $ */
 
 /*
  * Copyright 1999-2021,2022 by Thomas E. Dickey
@@ -1431,7 +1431,7 @@
 #define _NET_WM_STATE_TOGGLE	2	/* toggle property */
 
 extern Bool non_blank_line (TScreen */* screen */, int  /* row */, int  /* col */, int  /* len */);
-extern Char * allocScrnData (TScreen * /* screen */, unsigned /* nrow */, unsigned /* ncol */);
+extern Char * allocScrnData (TScreen * /* screen */, unsigned /* nrow */, unsigned /* ncol */, Bool /* bottom */);
 extern ScrnBuf allocScrnBuf (XtermWidget /* xw */, unsigned  /* nrow */, unsigned  /* ncol */, ScrnPtr * /* addr */);
 extern ScrnBuf scrnHeadAddr (TScreen * /* screen */, ScrnBuf /* base */, unsigned /* offset */);
 extern size_t ScrnPointers (TScreen * /* screen */, size_t  /* len */);
@@ -1455,7 +1455,7 @@
 extern void ScrnUpdate (XtermWidget /* xw */, int  /* toprow */, int  /* leftcol */, int  /* nrows */, int  /* ncols */, Bool  /* force */);
 extern void ScrnWriteText (XtermWidget /* xw */, IChar * /* str */, unsigned  /* flags */, CellColor /* cur_fg_bg */, unsigned  /* length */);
 extern void ShowWrapMarks (XtermWidget /* xw */, int /* row */, CLineData * /* ld */);
-extern void setupLineData (TScreen * /* screen */, ScrnBuf /* base */, Char * /* data */, unsigned /* nrow */, unsigned /* ncol */);
+extern void setupLineData (TScreen * /* screen */, ScrnBuf /* base */, Char * /* data */, unsigned /* nrow */, unsigned /* ncol */, Bool /* bottom */);
 extern void xtermParseRect (XtermWidget /* xw */, int, int *, XTermRect *);
 
 #if OPT_TRACE && OPT_TRACE_FLAGS
Index: xterm.log.html
--- xterm-371+/xterm.log.html	2022-02-24 09:11:30.000000000 +0000
+++ xterm-372/xterm.log.html	2022-03-10 01:00:00.000000000 +0000
@@ -30,7 +30,7 @@
  * sale, use or other dealings in this Software without prior written        *
  * authorization.                                                            *
  *****************************************************************************
-  $XTermId: xterm.log.html,v 1.2403 2022/02/24 09:11:30 tom Exp $
+  $XTermId: xterm.log.html,v 1.2406 2022/03/10 01:00:00 tom Exp $
   -->
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
 <html>
@@ -70,6 +70,8 @@
   CHANGELOG</a>).</p>
 
   <ul>
+    <li><a href="#xterm_372">Patch #372 - 2022/03/09</a></li>
+
     <li><a href="#xterm_371">Patch #371 - 2022/02/24</a></li>
 
     <li><a href="#xterm_370">Patch #370 - 2021/11/13</a></li>
@@ -1020,6 +1022,16 @@
     <li><a href="#xterm_01">Patch #1 - 1996/1/6</a></li>
   </ul>
 
+  <h1><a name="xterm_372" id="xterm_372">Patch #372 -
+  2022/03/09</a></h1>
+
+  <ul>
+    <li>amend allocation/freeing of scrollback lines, eliminating
+    an adjustment for status-line added in <a href=
+    "#xterm_371">patch #371</a> (report/testcase by Rajeev V.
+    Pillai).</li>
+  </ul>
+
   <h1><a name="xterm_371" id="xterm_371">Patch #371 -
   2022/02/24</a></h1>
 
