I think I finally tracked down a bug in the ascii driver which has been 
annoying me for 
years.  The bug is difficult to reproduce, since it manifests itself only when 
output
is to the terminal and exactly if and when it occurs is likely to be dependent 
on the
terminal's dimensions.

However I think the attached patches solve the problem.  I'm sending them here 
for review
before I check them in.

J'

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://keys.gnupg.net or any PGP keyserver for public key.

From 3e80fa93009664219ac7d27c2de530e8b6d82b13 Mon Sep 17 00:00:00 2001
From: John Darrington <[email protected]>
Date: Sat, 25 Feb 2012 12:15:03 +0100
Subject: [PATCH 1/4] ascii.c (ascii_reserve) Added assertion.

Added this assertion to catch a yet-to-be fixed array bounds bug.
---
 src/output/ascii.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/output/ascii.c b/src/output/ascii.c
index 1c3e6b8..7804ade 100644
--- a/src/output/ascii.c
+++ b/src/output/ascii.c
@@ -749,7 +749,9 @@ find_ascii_pos (struct ascii_line *line, int target_x, struct ascii_pos *c)
 static char *
 ascii_reserve (struct ascii_driver *a, int y, int x0, int x1, int n)
 {
-  struct ascii_line *line = &a->lines[y];
+  struct ascii_line *line;
+  assert (y < a->allocated_lines);
+  line = &a->lines[y];
 
   if (x0 >= line->width)
     {
-- 
1.7.2.5

From 0d24fd9f8579826fb51c6a8fbcbb68f243df235b Mon Sep 17 00:00:00 2001
From: John Darrington <[email protected]>
Date: Sat, 25 Feb 2012 12:22:32 +0100
Subject: [PATCH 2/4] ascii.c: Move auto out of the #if HAVE_DECL_SIGWINCH condtional

Whether or not the width/length should be automatic should depend only on whether the
output is a terminal, and not upon the existance of SIGWINCH
---
 src/output/ascii.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/output/ascii.c b/src/output/ascii.c
index 7804ade..d121987 100644
--- a/src/output/ascii.c
+++ b/src/output/ascii.c
@@ -1085,19 +1085,19 @@ ascii_open_page (struct ascii_driver *a)
       a->file = fn_open (a->file_name, a->append ? "a" : "w");
       if (a->file != NULL)
         {
-#if HAVE_DECL_SIGWINCH
 	  if ( isatty (fileno (a->file)))
 	    {
+#if HAVE_DECL_SIGWINCH
 	      struct sigaction action;
 	      sigemptyset (&action.sa_mask);
 	      action.sa_flags = 0;
 	      action.sa_handler = winch_handler;
 	      the_driver = a;
+	      sigaction (SIGWINCH, &action, NULL);
+#endif
 	      a->auto_width = true;
 	      a->auto_length = true;
-	      sigaction (SIGWINCH, &action, NULL);
 	    }
-#endif
         }
       else
         {
-- 
1.7.2.5

From 129424d546bbd4d7825be0f86cf05dcf5ce5eb07 Mon Sep 17 00:00:00 2001
From: John Darrington <[email protected]>
Date: Sat, 25 Feb 2012 14:28:20 +0100
Subject: [PATCH 3/4] Remove redundant assignment

---
 src/output/ascii.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/src/output/ascii.c b/src/output/ascii.c
index d121987..e66f2a1 100644
--- a/src/output/ascii.c
+++ b/src/output/ascii.c
@@ -955,7 +955,6 @@ ascii_layout_cell (struct ascii_driver *a, const struct table_cell *cell,
   if (length == 0)
     return;
 
-  text = cell->contents;
   breaks = xmalloc (length + 1);
   u8_possible_linebreaks (CHAR_CAST (const uint8_t *, text), length,
                           "UTF-8", breaks);
-- 
1.7.2.5

From e77d11a313bf23094e0c3185247ee800f250ad7f Mon Sep 17 00:00:00 2001
From: John Darrington <[email protected]>
Date: Sat, 25 Feb 2012 14:59:14 +0100
Subject: [PATCH 4/4] ascii.c: Reallocate the lines after the page is resized

---
 src/output/ascii.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/output/ascii.c b/src/output/ascii.c
index e66f2a1..1688fd1 100644
--- a/src/output/ascii.c
+++ b/src/output/ascii.c
@@ -202,6 +202,24 @@ static void ascii_draw_cell (void *, const struct table_cell *,
                              int bb[TABLE_N_AXES][2],
                              int clip[TABLE_N_AXES][2]);
 
+static void
+reallocate_lines (struct ascii_driver *a)
+{
+  if (a->length > a->allocated_lines)
+    {
+      int i;
+      a->lines = xnrealloc (a->lines, a->length, sizeof *a->lines);
+      for (i = a->allocated_lines; i < a->length; i++)
+        {
+          struct ascii_line *line = &a->lines[i];
+          ds_init_empty (&line->s);
+          line->width = 0;
+        }
+      a->allocated_lines = a->length;
+    }
+}
+
+
 static struct ascii_driver *
 ascii_driver_cast (struct output_driver *driver)
 {
@@ -340,6 +358,8 @@ update_page_size (struct ascii_driver *a, bool issue_error)
       return false;
     }
 
+  reallocate_lines (a);
+
   return true;
 }
 
@@ -1109,17 +1129,7 @@ ascii_open_page (struct ascii_driver *a)
 
   a->page_number++;
 
-  if (a->length > a->allocated_lines)
-    {
-      a->lines = xnrealloc (a->lines, a->length, sizeof *a->lines);
-      for (i = a->allocated_lines; i < a->length; i++)
-        {
-          struct ascii_line *line = &a->lines[i];
-          ds_init_empty (&line->s);
-          line->width = 0;
-        }
-      a->allocated_lines = a->length;
-    }
+  reallocate_lines (a);
 
   for (i = 0; i < a->length; i++)
     {
-- 
1.7.2.5

Attachment: signature.asc
Description: Digital signature

_______________________________________________
pspp-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/pspp-dev

Reply via email to