]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/hardscroll.c
ncurses 6.4 - patch 20240414
[ncurses.git] / ncurses / tty / hardscroll.c
index 4ec168a0028ecebf06e02e5ea36088c691574f5f..2b1f079e4b9eccd57968492e1f3efd63674cefe5 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc.              *
+ * Copyright 2020,2023 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.51 2012/10/17 09:01:10 tom Exp $")
+MODULE_ID("$Id: hardscroll.c,v 1.58 2023/09/09 16:04:08 Nicholas.Marriott Exp $")
 
 #if defined(SCROLLDEBUG) || defined(HASHDEBUG)
 
@@ -203,13 +204,19 @@ NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_DCL0)
        int *new_oldnums = typeRealloc(int,
                                       (size_t) need_lines,
                                       oldnums(SP_PARM));
-       if (!new_oldnums)
+       if (!new_oldnums) {
+           TR(TRACE_ICALLS, (T_RETURN("")));
            return;
+       }
        oldnums(SP_PARM) = new_oldnums;
        OLDNUM_SIZE(SP_PARM) = need_lines;
     }
     /* calculate the indices */
     NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_ARG);
+    if (SP_PARM->hashtab_len < screen_lines(SP_PARM)) {
+       TR(TRACE_ICALLS, (T_RETURN("")));
+       return;
+    }
 #endif
 #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
 
@@ -300,19 +307,27 @@ 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;
-
-    if ((buf = typeMalloc(char, want)) != 0) {
-
-       *buf = '\0';
-       for (n = 0; n < screen_lines(SP_PARM); n++)
-           _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);
+    if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) {
+       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++) {
+               int number = OLDNUM(SP_PARM, n);
+               if (number >= -99 && number < 999) {
+                   _nc_SPRINTF(buf + strlen(buf),
+                               _nc_SLIMIT(want - strlen(buf))
+                               " %02d", number);
+               } else {
+                   _nc_STRCAT(buf, " ??", want - strlen(buf));
+               }
+           }
+           free(buf);
+       }
     }
 }
 
@@ -339,7 +354,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 */