Module Name: src
Committed By: blymn
Date: Sun Jun 6 05:06:44 UTC 2021
Modified Files:
src/lib/libcurses: addbytes.c
Log Message:
Fix for PR lib/56224
Correct addstr behaviour so it truncates the string in the case where
a string is added on the bottom line of a window where scrolling is
disabled as per the SUSv2 specification.
To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/lib/libcurses/addbytes.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libcurses/addbytes.c
diff -u src/lib/libcurses/addbytes.c:1.54 src/lib/libcurses/addbytes.c:1.55
--- src/lib/libcurses/addbytes.c:1.54 Sat Feb 13 14:30:37 2021
+++ src/lib/libcurses/addbytes.c Sun Jun 6 05:06:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: addbytes.c,v 1.54 2021/02/13 14:30:37 rillig Exp $ */
+/* $NetBSD: addbytes.c,v 1.55 2021/06/06 05:06:44 blymn Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: addbytes.c,v 1.54 2021/02/13 14:30:37 rillig Exp $");
+__RCSID("$NetBSD: addbytes.c,v 1.55 2021/06/06 05:06:44 blymn Exp $");
#endif
#endif /* not lint */
@@ -170,6 +170,15 @@ _cursesi_waddbytes(WINDOW *win, const ch
} else if (wc == 0) {
break;
}
+
+ /* if scrollok is false and we are at the bottom of
+ * screen and this character would take us past the
+ * end of the line then we are done.
+ */
+ if ((win->curx + n >= win->maxx) &&
+ (!(win->flags & __SCROLLOK)) &&
+ (win->cury == win->scr_b))
+ break;
#ifdef DEBUG
__CTRACE(__CTRACE_INPUT,
"ADDBYTES WIDE(0x%x [%s], %x) at (%d, %d), ate %d bytes\n",
@@ -214,6 +223,19 @@ _cursesi_addbyte(WINDOW *win, __LINE **l
case '\t':
tabsize = win->screen->TABSIZE;
newx = tabsize - (*x % tabsize);
+ /* if at the bottom of the window and
+ not allowed to scroll then just do
+ what we can */
+ if ((*y == win->scr_b) &&
+ !(win->flags & __SCROLLOK)) {
+ if ((*lp)->flags & __ISPASTEOL) {
+ return OK;
+ }
+
+ if (*x + newx > win->maxx - 1)
+ newx = win->maxx - *x - 1;
+ }
+
for (i = 0; i < newx; i++) {
if (waddbytes(win, blank, 1) == ERR)
return ERR;
@@ -366,6 +388,20 @@ _cursesi_addwchar(WINDOW *win, __LINE **
cc.attributes = win->wattr;
tabsize = win->screen->TABSIZE;
newx = tabsize - (*x % tabsize);
+
+ /* if at the bottom of the window and
+ not allowed to scroll then just do
+ what we can */
+ if ((*y == win->scr_b) &&
+ !(win->flags & __SCROLLOK)) {
+ if ((*lnp)->flags & __ISPASTEOL) {
+ return OK;
+ }
+
+ if (*x + newx > win->maxx - 1)
+ newx = win->maxx - *x - 1;
+ }
+
for (i = 0; i < newx; i++) {
if (wadd_wch(win, &cc) == ERR)
return ERR;