Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses Fix for PR lib/56224



details:   https://anonhg.NetBSD.org/src/rev/4dd3d799c06b
branches:  trunk
changeset: 983788:4dd3d799c06b
user:      blymn <blymn%NetBSD.org@localhost>
date:      Sun Jun 06 05:06:44 2021 +0000

description:
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.

diffstat:

 lib/libcurses/addbytes.c |  40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diffs (75 lines):

diff -r f0c7f34671e8 -r 4dd3d799c06b lib/libcurses/addbytes.c
--- a/lib/libcurses/addbytes.c  Sun Jun 06 04:59:36 2021 +0000
+++ b/lib/libcurses/addbytes.c  Sun Jun 06 05:06:44 2021 +0000
@@ -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 @@
                } 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 @@
                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 @@
                        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;



Home | Main Index | Thread Index | Old Index