Tue Jun 1 00:59:02 2021 UTC ()
Fix initial line hash calculation for subwindows

lp->hash is not initialized at this point. Since the hash is
calculated in chunks using __hash_more(), it needs to be initialized
to 0 first (just as in doupdate()).

Detected with valgrind while running python's test suite when
debugging an unrelated issue.

ok uwe@


(mcf)
diff -r1.59 -r1.60 src/lib/libcurses/newwin.c

cvs diff -r1.59 -r1.60 src/lib/libcurses/newwin.c (expand / switch to unified diff)

--- src/lib/libcurses/newwin.c 2021/05/15 11:06:07 1.59
+++ src/lib/libcurses/newwin.c 2021/06/01 00:59:01 1.60
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: newwin.c,v 1.59 2021/05/15 11:06:07 uwe Exp $ */ 1/* $NetBSD: newwin.c,v 1.60 2021/06/01 00:59:01 mcf Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1981, 1993, 1994 4 * Copyright (c) 1981, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94"; 35static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94";
36#else 36#else
37__RCSID("$NetBSD: newwin.c,v 1.59 2021/05/15 11:06:07 uwe Exp $"); 37__RCSID("$NetBSD: newwin.c,v 1.60 2021/06/01 00:59:01 mcf Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdlib.h> 41#include <stdlib.h>
42 42
43#include "curses.h" 43#include "curses.h"
44#include "curses_private.h" 44#include "curses_private.h"
45 45
46 46
47static WINDOW *__makenew(SCREEN *screen, int nlines, int ncols, int by, 47static WINDOW *__makenew(SCREEN *screen, int nlines, int ncols, int by,
48 int bx, int sub, int ispad); 48 int bx, int sub, int ispad);
49static WINDOW *__subwin(WINDOW *orig, int nlines, int ncols, int by, int bx, 49static WINDOW *__subwin(WINDOW *orig, int nlines, int ncols, int by, int bx,
50 int ispad); 50 int ispad);
@@ -242,26 +242,27 @@ __set_subwin(WINDOW *orig, WINDOW *win) @@ -242,26 +242,27 @@ __set_subwin(WINDOW *orig, WINDOW *win)
242 for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) { 242 for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) {
243 win->alines[i] = lp; 243 win->alines[i] = lp;
244 olp = orig->alines[i + win->begy - orig->begy]; 244 olp = orig->alines[i + win->begy - orig->begy];
245#ifdef DEBUG 245#ifdef DEBUG
246 lp->sentinel = SENTINEL_VALUE; 246 lp->sentinel = SENTINEL_VALUE;
247#endif 247#endif
248 lp->line = &olp->line[win->ch_off]; 248 lp->line = &olp->line[win->ch_off];
249 lp->firstchp = &olp->firstch; 249 lp->firstchp = &olp->firstch;
250 lp->lastchp = &olp->lastch; 250 lp->lastchp = &olp->lastch;
251#ifndef HAVE_WCHAR 251#ifndef HAVE_WCHAR
252 lp->hash = __hash((char *)(void *)lp->line, 252 lp->hash = __hash((char *)(void *)lp->line,
253 (size_t)(win->maxx * __LDATASIZE)); 253 (size_t)(win->maxx * __LDATASIZE));
254#else 254#else
 255 lp->hash = 0;
255 for (cp = lp->line, j = 0; j < win->maxx; j++, cp++) { 256 for (cp = lp->line, j = 0; j < win->maxx; j++, cp++) {
256 lp->hash = __hash_more( &cp->ch, 257 lp->hash = __hash_more( &cp->ch,
257 sizeof( wchar_t ), lp->hash ); 258 sizeof( wchar_t ), lp->hash );
258 lp->hash = __hash_more( &cp->attr, 259 lp->hash = __hash_more( &cp->attr,
259 sizeof( wchar_t ), lp->hash ); 260 sizeof( wchar_t ), lp->hash );
260 if ( cp->nsp ) { 261 if ( cp->nsp ) {
261 np = cp->nsp; 262 np = cp->nsp;
262 while ( np ) { 263 while ( np ) {
263 lp->hash = __hash_more( &np->ch, 264 lp->hash = __hash_more( &np->ch,
264 sizeof( wchar_t ), lp->hash ); 265 sizeof( wchar_t ), lp->hash );
265 np = np->next; 266 np = np->next;
266 } 267 }
267 } 268 }