]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/hardscroll.c
ncurses 6.2 - patch 20201017
[ncurses.git] / ncurses / tty / hardscroll.c
index 6c6052570d3427d6f7c4f3401d4d46adcba4234a..abb21cfddfe327a3ce58dc062756e8f8071ab926 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc.              *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 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 +148,7 @@ AUTHOR
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: hardscroll.c,v 1.49 2012/02/22 22:40:24 tom Exp $")
+MODULE_ID("$Id: hardscroll.c,v 1.54 2020/02/02 23:34:34 tom Exp $")
 
 #if defined(SCROLLDEBUG) || defined(HASHDEBUG)
 
@@ -193,14 +194,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);
@@ -294,11 +301,12 @@ 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 = ((size_t) screen_lines(SP_PARM) + 1) * 4;
+    (void) SP_PARM;
 
     if ((buf = typeMalloc(char, want)) != 0) {
+       int n;
 
        *buf = '\0';
        for (n = 0; n < screen_lines(SP_PARM); n++)
@@ -333,7 +341,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 */