X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftty%2Fhardscroll.c;h=f7c9e0d46f5295b95525da1cdc45da3fa02404f5;hp=85d570a7fdee951bfea386bc8345cabbb04fb51c;hb=e348f7adec279f5453349ad13246a952a16e2094;hpb=f5da57ad7eb397b1001e2fca9cb0e278a6564716 diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c index 85d570a7..f7c9e0d4 100644 --- a/ncurses/tty/hardscroll.c +++ b/ncurses/tty/hardscroll.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. * + * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -147,7 +147,7 @@ AUTHOR #include -MODULE_ID("$Id: hardscroll.c,v 1.45 2009/11/07 16:06:42 tom Exp $") +MODULE_ID("$Id: hardscroll.c,v 1.53 2016/05/28 23:32:40 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -173,9 +173,9 @@ NCURSES_EXPORT_VAR (int *) # if USE_HASHMAP # define oldnums(sp) (sp)->_oldnum_list # define OLDNUM(sp,n) oldnums(sp)[n] -# else /* !USE_HASHMAP */ +# else /* !USE_HASHMAP */ # define OLDNUM(sp,n) NewScreen(sp)->_line[n].oldindex -# endif /* !USE_HASHMAP */ +# endif /* !USE_HASHMAP */ #define OLDNUM_SIZE(sp) (sp)->_oldnum_size @@ -193,12 +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)) { - int *new_oldnums = typeRealloc(int, screen_lines(SP_PARM), oldnums(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) 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); @@ -292,16 +300,19 @@ NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_linedump) (NCURSES_SP_DCL0) /* dump the state of the real and virtual oldnum fields */ { - int n; char *buf = 0; - size_t want = (screen_lines(SP_PARM) + 1) * 4; + size_t want = ((size_t) screen_lines(SP_PARM) + 1) * 4; + (void) SP_PARM; if ((buf = typeMalloc(char, want)) != 0) { + int n; - (void) strcpy(buf, "virt"); + *buf = '\0'; for (n = 0; n < screen_lines(SP_PARM); n++) - (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(SP_PARM, n)); - TR(TRACE_UPDATE | TRACE_MOVE, (buf)); + _nc_SPRINTF(buf + strlen(buf), + _nc_SLIMIT(want - strlen(buf)) + " %02d", OLDNUM(SP_PARM, n)); + TR(TRACE_UPDATE | TRACE_MOVE, ("virt %s", buf)); free(buf); } } @@ -329,7 +340,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) for (;;) { int n; - for (n = 0; n < screen_lines; n++) + for (n = 0; n < screen_lines(sp); n++) oldnums[n] = _NEWINDEX; /* grab the test vector */