Source-Changes-HG archive

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

[src/trunk]: src/lib/libcurses PR lib/56388



details:   https://anonhg.NetBSD.org/src/rev/dc033942db16
branches:  trunk
changeset: 985764:dc033942db16
user:      rin <rin%NetBSD.org@localhost>
date:      Tue Sep 07 01:23:09 2021 +0000

description:
PR lib/56388

For __newwin() and __resizewin(), the line hash was calculated as if
HAVE_WCHAR is disabled.

Fix this bug by refactoring __hash_line() function, which calculates
the line hash by an appropriate method.

diffstat:

 lib/libcurses/cur_hash.c       |  26 ++++++++++++++++++++++++--
 lib/libcurses/curses_private.h |   3 ++-
 lib/libcurses/newwin.c         |  33 ++++-----------------------------
 lib/libcurses/refresh.c        |  37 ++++---------------------------------
 lib/libcurses/resize.c         |   7 +++----
 5 files changed, 37 insertions(+), 69 deletions(-)

diffs (222 lines):

diff -r bd88c407017d -r dc033942db16 lib/libcurses/cur_hash.c
--- a/lib/libcurses/cur_hash.c  Mon Sep 06 21:56:03 2021 +0000
+++ b/lib/libcurses/cur_hash.c  Tue Sep 07 01:23:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cur_hash.c,v 1.13 2017/01/06 09:14:07 roy Exp $        */
+/*     $NetBSD: cur_hash.c,v 1.14 2021/09/07 01:23:09 rin Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)cur_hash.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: cur_hash.c,v 1.13 2017/01/06 09:14:07 roy Exp $");
+__RCSID("$NetBSD: cur_hash.c,v 1.14 2021/09/07 01:23:09 rin Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -63,3 +63,25 @@
        }
        return h;
 }
+
+unsigned int
+__hash_line(const __LDATA *cp, int ncols)
+{
+#ifdef HAVE_WCHAR
+       unsigned int h;
+       const nschar_t *np;
+       int x;
+
+       h = 0;
+       for (x = 0; x < ncols; x++) {
+               h = __hash_more(&cp->ch, sizeof(cp->ch), h);
+               h = __hash_more(&cp->attr, sizeof(cp->attr), h);
+               for (np = cp->nsp; np != NULL; np = np->next)
+                       h = __hash_more(&np->ch, sizeof(np->ch), h);
+               cp++;
+       }
+       return h;
+#else
+       return __hash(cp, (size_t)(ncols * __LDATASIZE));
+#endif
+}
diff -r bd88c407017d -r dc033942db16 lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h    Mon Sep 06 21:56:03 2021 +0000
+++ b/lib/libcurses/curses_private.h    Tue Sep 07 01:23:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_private.h,v 1.75 2021/09/06 07:03:49 rin Exp $  */
+/*     $NetBSD: curses_private.h,v 1.76 2021/09/07 01:23:09 rin Exp $  */
 
 /*-
  * Copyright (c) 1998-2000 Brett Lymn
@@ -373,6 +373,7 @@
 int      _cursesi_setterm(char *, SCREEN *);
 int     __delay(void);
 unsigned int    __hash_more(const void *, size_t, unsigned int);
+unsigned int    __hash_line(const __LDATA *, int);
 #define        __hash(s, len)  __hash_more((s), (len), 0u)
 void    __id_subwins(WINDOW *);
 void    __init_getch(SCREEN *);
diff -r bd88c407017d -r dc033942db16 lib/libcurses/newwin.c
--- a/lib/libcurses/newwin.c    Mon Sep 06 21:56:03 2021 +0000
+++ b/lib/libcurses/newwin.c    Tue Sep 07 01:23:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newwin.c,v 1.61 2021/09/06 07:03:50 rin Exp $  */
+/*     $NetBSD: newwin.c,v 1.62 2021/09/07 01:23:09 rin Exp $  */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)newwin.c   8.3 (Berkeley) 7/27/94";
 #else
-__RCSID("$NetBSD: newwin.c,v 1.61 2021/09/06 07:03:50 rin Exp $");
+__RCSID("$NetBSD: newwin.c,v 1.62 2021/09/07 01:23:09 rin Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -169,8 +169,7 @@
                        SET_WCOL(*sp, 1);
 #endif /* HAVE_WCHAR */
                }
-               lp->hash = __hash((char *)(void *)lp->line,
-                                 (size_t)(maxx * __LDATASIZE));
+               lp->hash = __hash_line(lp->line, maxx);
        }
        return (win);
 }
@@ -227,11 +226,6 @@
 {
        int     i;
        __LINE *lp, *olp;
-#ifdef HAVE_WCHAR
-       __LDATA *cp;
-       int j;
-       nschar_t *np;
-#endif /* HAVE_WCHAR */
 
        win->ch_off = win->begx - orig->begx;
        /* Point line pointers to line space. */
@@ -244,26 +238,7 @@
                lp->line = &olp->line[win->ch_off];
                lp->firstchp = &olp->firstch;
                lp->lastchp = &olp->lastch;
-#ifndef HAVE_WCHAR
-               lp->hash = __hash((char *)(void *)lp->line,
-                                 (size_t)(win->maxx * __LDATASIZE));
-#else
-               lp->hash = 0;
-               for (cp = lp->line, j = 0; j < win->maxx; j++, cp++) {
-                       lp->hash = __hash_more( &cp->ch,
-                           sizeof( wchar_t ), lp->hash );
-                       lp->hash = __hash_more( &cp->attr,
-                           sizeof( wchar_t ), lp->hash );
-                       if ( cp->nsp ) {
-                               np = cp->nsp;
-                               while ( np ) {
-                                       lp->hash = __hash_more( &np->ch,
-                                           sizeof( wchar_t ), lp->hash );
-                                       np = np->next;
-                               }
-                       }
-               }
-#endif /* HAVE_WCHAR */
+               lp->hash = __hash_line(lp->line, win->maxx);
        }
 
        __CTRACE(__CTRACE_WINDOW, "__set_subwin: win->ch_off = %d\n",
diff -r bd88c407017d -r dc033942db16 lib/libcurses/refresh.c
--- a/lib/libcurses/refresh.c   Mon Sep 06 21:56:03 2021 +0000
+++ b/lib/libcurses/refresh.c   Tue Sep 07 01:23:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: refresh.c,v 1.115 2021/09/06 07:45:48 rin Exp $        */
+/*     $NetBSD: refresh.c,v 1.116 2021/09/07 01:23:09 rin Exp $        */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)refresh.c  8.7 (Berkeley) 8/13/94";
 #else
-__RCSID("$NetBSD: refresh.c,v 1.115 2021/09/06 07:45:48 rin Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.116 2021/09/07 01:23:09 rin Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -515,11 +515,6 @@
        __LINE  *wlp, *vlp;
        short    wy;
        int      dnum, was_cleared, changed;
-#ifdef HAVE_WCHAR
-       __LDATA *lp;
-       nschar_t *np;
-       int x;
-#endif /* HAVE_WCHAR */
 
        /* Check if we need to restart ... */
        if (_cursesi_screen->endwin)
@@ -538,32 +533,8 @@
        if (!_cursesi_screen->curwin) {
                for (wy = 0; wy < win->maxy; wy++) {
                        wlp = win->alines[wy];
-                       if (wlp->flags & __ISDIRTY) {
-#ifndef HAVE_WCHAR
-                               wlp->hash = __hash(wlp->line,
-                                   (size_t)(win->maxx * __LDATASIZE));
-#else
-                               wlp->hash = 0;
-                               for ( x = 0; x < win->maxx; x++ ) {
-                                       lp = &wlp->line[ x ];
-                                       wlp->hash = __hash_more( &lp->ch,
-                                               sizeof(wchar_t), wlp->hash );
-                                       wlp->hash = __hash_more( &lp->attr,
-                                               sizeof(attr_t), wlp->hash );
-                                       np = lp->nsp;
-                                       if (np) {
-                                               while (np) {
-                                                       wlp->hash
-                                                           = __hash_more(
-                                                               &np->ch,
-                                                               sizeof(wchar_t),
-                                                               wlp->hash);
-                                                       np = np->next;
-                                               }
-                                       }
-                               }
-#endif /* HAVE_WCHAR */
-                       }
+                       if (wlp->flags & __ISDIRTY)
+                               wlp->hash = __hash_line(wlp->line, win->maxx);
                }
        }
 
diff -r bd88c407017d -r dc033942db16 lib/libcurses/resize.c
--- a/lib/libcurses/resize.c    Mon Sep 06 21:56:03 2021 +0000
+++ b/lib/libcurses/resize.c    Tue Sep 07 01:23:09 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize.c,v 1.32 2021/09/06 07:03:50 rin Exp $  */
+/*     $NetBSD: resize.c,v 1.33 2021/09/07 01:23:09 rin Exp $  */
 
 /*
  * Copyright (c) 2001
@@ -33,7 +33,7 @@
 #if 0
 static char sccsid[] = "@(#)resize.c   blymn 2001/08/26";
 #else
-__RCSID("$NetBSD: resize.c,v 1.32 2021/09/06 07:03:50 rin Exp $");
+__RCSID("$NetBSD: resize.c,v 1.33 2021/09/07 01:23:09 rin Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -360,8 +360,7 @@
                        SET_WCOL(*sp, 1);
 #endif /* HAVE_WCHAR */
                }
-               lp->hash = __hash((char *)(void *)lp->line,
-                                 (size_t)(ncols * __LDATASIZE));
+               lp->hash = __hash_line(lp->line, ncols);
        }
 
        __CTRACE(__CTRACE_WINDOW, "resize: win->wattr = %08x\n", win->wattr);



Home | Main Index | Thread Index | Old Index