X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftty%2Fhardscroll.c;h=4ec168a0028ecebf06e02e5ea36088c691574f5f;hp=6c6052570d3427d6f7c4f3401d4d46adcba4234a;hb=17d9459c7aecedecbfc59b8ba5d29279a01e9003;hpb=8b06e371ed1bce3dd6f37138e6becb5e1a562fe0 diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c index 6c605257..4ec168a0 100644 --- a/ncurses/tty/hardscroll.c +++ b/ncurses/tty/hardscroll.c @@ -147,7 +147,7 @@ AUTHOR #include -MODULE_ID("$Id: hardscroll.c,v 1.49 2012/02/22 22:40:24 tom Exp $") +MODULE_ID("$Id: hardscroll.c,v 1.51 2012/10/17 09:01:10 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -193,14 +193,20 @@ NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_DCL0) #if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) #if USE_HASHMAP /* get enough storage */ - if (OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM)) { + assert(OLDNUM_SIZE(SP_PARM) >= 0); + assert(screen_lines(SP_PARM) > 0); + if ((oldnums(SP_PARM) == 0) + || (OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM))) { + int need_lines = ((OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM)) + ? screen_lines(SP_PARM) + : OLDNUM_SIZE(SP_PARM)); int *new_oldnums = typeRealloc(int, - (size_t) screen_lines(SP_PARM), + (size_t) need_lines, oldnums(SP_PARM)); if (!new_oldnums) return; oldnums(SP_PARM) = new_oldnums; - OLDNUM_SIZE(SP_PARM) = screen_lines(SP_PARM); + OLDNUM_SIZE(SP_PARM) = need_lines; } /* calculate the indices */ NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_ARG);