Module Name: src Committed By: rin Date: Tue Sep 7 01:23:10 UTC 2021
Modified Files: src/lib/libcurses: cur_hash.c curses_private.h newwin.c refresh.c resize.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/lib/libcurses/cur_hash.c cvs rdiff -u -r1.75 -r1.76 src/lib/libcurses/curses_private.h cvs rdiff -u -r1.61 -r1.62 src/lib/libcurses/newwin.c cvs rdiff -u -r1.115 -r1.116 src/lib/libcurses/refresh.c cvs rdiff -u -r1.32 -r1.33 src/lib/libcurses/resize.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/cur_hash.c diff -u src/lib/libcurses/cur_hash.c:1.13 src/lib/libcurses/cur_hash.c:1.14 --- src/lib/libcurses/cur_hash.c:1.13 Fri Jan 6 09:14:07 2017 +++ src/lib/libcurses/cur_hash.c Tue Sep 7 01:23:09 2021 @@ -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 @@ __hash_more(const void *v_s, size_t len } 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 +} Index: src/lib/libcurses/curses_private.h diff -u src/lib/libcurses/curses_private.h:1.75 src/lib/libcurses/curses_private.h:1.76 --- src/lib/libcurses/curses_private.h:1.75 Mon Sep 6 07:03:49 2021 +++ src/lib/libcurses/curses_private.h Tue Sep 7 01:23:09 2021 @@ -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 @@ void _cursesi_resetterm(SCREEN *); 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 *); Index: src/lib/libcurses/newwin.c diff -u src/lib/libcurses/newwin.c:1.61 src/lib/libcurses/newwin.c:1.62 --- src/lib/libcurses/newwin.c:1.61 Mon Sep 6 07:03:50 2021 +++ src/lib/libcurses/newwin.c Tue Sep 7 01:23:09 2021 @@ -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 @@ __newwin(SCREEN *screen, int nlines, int 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 @@ __set_subwin(WINDOW *orig, WINDOW *win) { 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 @@ __set_subwin(WINDOW *orig, WINDOW *win) 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", Index: src/lib/libcurses/refresh.c diff -u src/lib/libcurses/refresh.c:1.115 src/lib/libcurses/refresh.c:1.116 --- src/lib/libcurses/refresh.c:1.115 Mon Sep 6 07:45:48 2021 +++ src/lib/libcurses/refresh.c Tue Sep 7 01:23:09 2021 @@ -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 @@ doupdate(void) __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 @@ doupdate(void) 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); } } Index: src/lib/libcurses/resize.c diff -u src/lib/libcurses/resize.c:1.32 src/lib/libcurses/resize.c:1.33 --- src/lib/libcurses/resize.c:1.32 Mon Sep 6 07:03:50 2021 +++ src/lib/libcurses/resize.c Tue Sep 7 01:23:09 2021 @@ -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 @@ __resizewin(WINDOW *win, int nlines, int 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);