Control: tags -1 + patch

On 2023-12-10 20:18 +0100, Santiago Vila wrote:

> Package: src:ncurses-hexedit
> Version: 0.9.7+orig-7.2
> Severity: serious
> Tags: ftbfs
>
> Dear maintainer:
>
> During a rebuild of all packages in unstable, your package failed to build:
>
> --------------------------------------------------------------------------------
> [...]
> gcc -DHAVE_CONFIG_H -I. -I..  -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2
> -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong
> -fstack-clash-protection -Wformat -Werror=format-security
> -fcf-protection -Wall -c -o file.o file.c
> file.c: In function ‘printPage’:
> file.c:647:34: error: invalid use of incomplete typedef ‘WINDOW’ {aka ‘struct 
> _win_st’}
>   647 |       for (result = Globals.wmain->_curx; result < COLS; result++)
>       |                                  ^~

There are quite a few more instances of such errors across the source
code, the attached patch should fix all of them.  The package builds and
from a cursory look appears to work, but it would be good if a potential
NMU'er reviews and tests the patch before uploading.

Cheers,
       Sven

From 676299deb4fa83c7f100011da2948c49ba97499c Mon Sep 17 00:00:00 2001
From: Sven Joachim <svenj...@gmx.de>
Date: Sun, 17 Dec 2023 16:15:43 +0100
Subject: [PATCH] Avoid accessing internal ncurses structures

Since ncurses patchlevel 20231021 the WINDOW structure is opaque, its
members cannot be addressed directly.  Use the functions ncurses
provides for this purpose instead.
---
 src/file.c    |  2 +-
 src/misc.c    |  6 ++----
 src/print.c   | 16 ++++++++--------
 src/widgets.c | 24 ++++++++++++------------
 4 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/file.c b/src/file.c
index 14a2475..ba7c147 100644
--- a/src/file.c
+++ b/src/file.c
@@ -644,7 +644,7 @@ printPage (const struct FileNames *fp)
       wprintw (Globals.wmain, "%s", trunc_file);
       fp = fp->p;

-      for (result = Globals.wmain->_curx; result < COLS; result++)
+      for (result = getcurx(Globals.wmain); result < COLS; result++)
          wprintw (Globals.wmain, " ");
    }

diff --git a/src/misc.c b/src/misc.c
index 24068b4..8b0fb4b 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -641,10 +641,8 @@ handleSigwinch (int i)
    if (!newlines)
       die_horribly (NOT_ENOUGH_MEMORY, NULL);

-   Globals.wmain->_cury = cursor_y - 1;
-   Globals.wmain->_curx = cursor_x;
-   stdscr->_cury = cursor_y;
-   stdscr->_curx = cursor_x;
+   wmove(Globals.wmain, cursor_y - 1, cursor_x);
+   move(cursor_y, cursor_x);
    if (cursor_y >= BOTTOM_LINE)
       cursor_y = BOTTOM_LINE;
    if (Globals.mode == FILE_MODE)
diff --git a/src/print.c b/src/print.c
index 57b291e..59b0ca1 100644
--- a/src/print.c
+++ b/src/print.c
@@ -196,16 +196,16 @@ drawAsciiDump (unsigned long off, unsigned long *offs)
       if (*offs > Globals.filesize)
          break;
 #ifdef __NCURSES_H     /* i don't know why this works */
-      if (Globals.wmain->_cury == MAIN_BOTTOM_LINE)
+      if (getcury(Globals.wmain) == MAIN_BOTTOM_LINE)
 #else
-      if (Globals.wmain->_cury == MAIN_HEIGHT)
+      if (getcury(Globals.wmain) == MAIN_HEIGHT)
 #endif
          break;
-      if (Globals.wmain->_curx == COLS - 2)
+      if (getcurx(Globals.wmain) == COLS - 2)
       {
          move = 1;
       }
-      if (Globals.wmain->_curx == 0)
+      if (getcurx(Globals.wmain) == 0)
          *(newlines + i++) = *offs;
       bold = hash_lookup (*offs, NULL);
       if (!bold)
@@ -215,8 +215,8 @@ drawAsciiDump (unsigned long off, unsigned long *offs)
       {
          if (filebuffer (*offs) == '\n')
          {
-            int cury = Globals.wmain->_cury;
-            int i = Globals.wmain->_curx;
+            int cury = getcury(Globals.wmain);
+            int i = getcurx(Globals.wmain);
             for (; i < COLS - 2; i++)
                wprintw (Globals.wmain, " ");
             wprintw (Globals.wmain, ".");
@@ -235,7 +235,7 @@ drawAsciiDump (unsigned long off, unsigned long *offs)
       {
          if (filebuffer (*offs) == EBCDIC['\n'])
          {
-            int cury = Globals.wmain->_cury;
+            int cury = getcury(Globals.wmain);
             wprintw (Globals.wmain, ".");
             wmove (Globals.wmain, cury + 1, 0);
          }
@@ -257,7 +257,7 @@ drawAsciiDump (unsigned long off, unsigned long *offs)
       (*offs)++;
       if (move)
       {
-         wmove (Globals.wmain, Globals.wmain->_cury + 1, 0);
+         wmove (Globals.wmain, getcury(Globals.wmain) + 1, 0);
          move = 0;
          continue;
       }
diff --git a/src/widgets.c b/src/widgets.c
index eb627ad..38183f8 100644
--- a/src/widgets.c
+++ b/src/widgets.c
@@ -99,11 +99,11 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
          case KEY_LEFT:
             if (i > 0)
             {
-               if (win->_curx > x)
+               if (getcurx(win) > x)
                /* not at left hand side */
                {
                   i--;
-                  wmove (win, y, win->_curx - 1);
+                  wmove (win, y, getcurx(win) - 1);
                }
                else if (i > 0)
                /* left hand side */
@@ -128,11 +128,11 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
             }
             break;
          case KEY_RIGHT:
-            if (win->_curx < (x + max - 1))
+            if (getcurx(win) < (x + max - 1))
             /* not at right hand side */
             {
                i++;
-               wmove (win, y, win->_curx + 1);
+               wmove (win, y, getcurx(win) + 1);
             }
             else if (i < len - 1)
             /* right hand side */
@@ -163,7 +163,7 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
 #endif
             if (i > 0)
             {
-               if (win->_curx > x)
+	        if (getcurx(win) > x)
                /* not at left hand side */
                {
                   i--;
@@ -172,7 +172,7 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
                   for (n = i; n < len; n++)
                      *(str + n) = *(str + n + 1);
                   *(str + n) = 0;
-                  oldx = win->_curx;
+                  oldx = getcurx(win);
                   wmove (win, y, x);
                   for (n = left; n <= right; n++)
                   {
@@ -209,8 +209,8 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
                do_beep ();
             break;
          case SPACEBAR:
-            oldx = win->_curx;
-            if ((win->_curx < x + max - 1)
+            oldx = getcurx(win);
+            if ((getcurx(win) < x + max - 1)
              && (i < len - 1) && (*(str + len - 1) <= ' '))
             {
                for (n = len - 1; n > i; n--)
@@ -230,7 +230,7 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
                }
                wmove (win, y, oldx + 1);
             }
-            else if ((win->_curx == x + max - 1)
+            else if ((getcurx(win) == x + max - 1)
              && (i < len - 1) && (*(str + len - 1) <= ' '))
             {
                for (n = len - 1; n > i; n--)
@@ -255,7 +255,7 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
                }
                wmove (win, y, x + max - 1);
             }
-            else if ((win->_curx == x + max - 1)
+            else if ((getcurx(win) == x + max - 1)
              && (i == len - 1))
             {
                *(str + len - 1) = ' ';
@@ -285,12 +285,12 @@ stringBox (WINDOW *win, int y, int x, int len, int max, char *sample)
          default: /* normal input */
             if (isprintable (in))
             {
-               if (win->_curx != (x + max - 1))
+               if (getcurx(win) != (x + max - 1))
                /* not at right hand side */
                {
                   *(str + i) = in;
                   i++;
-                  oldx = win->_curx;
+                  oldx = getcurx(win);
                   wmove (win, y, x);
                   for (n = left; n <= right; n++)
                   {
--
2.43.0

Reply via email to