Html Driver: Fix bug when rendering small cells.
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 24 Mar 2017 16:40:39 +0000 (17:40 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 24 Mar 2017 19:37:40 +0000 (20:37 +0100)
This fix avoids a bug where the driver would enter a tight loop when rendering cells
with zero height or width.

NEWS
src/output/html.c
tests/automake.mk
tests/output/html.at [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5085b1fac0e1a689768c22d392c1d4d4a0b1fce0..141723b71f0d8dc8ee7acb6a624f0a546fdc7fce 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ Please send PSPP bug reports to bug-gnu-pspp@gnu.org.
 
 Changes from 0.10.2 to 0.10.4:
 
+ * A bug which could cause the HTML driver to go into a tight loop
+   has been fixed.
+
  * An error in the FREQUENCIES procedure, where the word "Mean" was
    printed when "Variance" was appropriate has been fixed.
 
index 8b16ffa780d29d07fc6cf8e9a2fdbab233ccd0ae..fd6d40d106f32d4f460fd4ca13db8b8e7f921e02 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2013, 2014, 2017 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -407,7 +407,6 @@ html_output_table (struct html_driver *html, const struct table_item *item)
   for (y = 0; y < table_nr (t); y++)
     {
       int x;
-
       for (x = 0; x < table_nc (t); )
         {
           const struct cell_contents *c;
@@ -415,7 +414,7 @@ html_output_table (struct html_driver *html, const struct table_item *item)
 
           table_get_cell (t, x, y, &cell);
           if (y != cell.d[TABLE_VERT][0])
-            continue;
+            goto next_0;
 
           for (c = cell.contents; c < &cell.contents[cell.n_contents]; c++)
             {
@@ -432,6 +431,8 @@ html_output_table (struct html_driver *html, const struct table_item *item)
                                  strlen (c->footnotes[i]), " ", "<BR>");
                 }
             }
+
+       next_0:
           x = cell.d[TABLE_HORZ][1];
           table_cell_free (&cell);
         }
@@ -465,7 +466,7 @@ html_output_table (struct html_driver *html, const struct table_item *item)
 
           table_get_cell (t, x, y, &cell);
           if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
-            continue;
+            goto next_1;
 
           /* Output <TD> or <TH> tag. */
           is_header = (y < table_ht (t)
@@ -570,6 +571,7 @@ html_output_table (struct html_driver *html, const struct table_item *item)
           /* Output </TH> or </TD>. */
           fprintf (html->file, "</%s>\n", tag);
 
+       next_1:
           x = cell.d[TABLE_HORZ][1];
           table_cell_free (&cell);
         }
index 0fe8a5f69ccfac230f39b9be9c3fdf0b190a182c..93b19d82d07d3258fae4d6c084e0863021f64cf7 100644 (file)
@@ -394,6 +394,7 @@ TESTSUITE_AT = \
        tests/math/randist.at \
        tests/output/ascii.at \
        tests/output/charts.at \
+       tests/output/html.at \
        tests/output/output.at \
        tests/output/paper-size.at \
        tests/output/render.at \
diff --git a/tests/output/html.at b/tests/output/html.at
new file mode 100644 (file)
index 0000000..9a048ca
--- /dev/null
@@ -0,0 +1,29 @@
+AT_BANNER([HTML driver])
+
+AT_SETUP([HTML bug])
+
+dnl Checks for a bug which caused the html driver to go into a tight loop.
+AT_DATA([foo.sps], [data list notable list /w l96_r l99_r l102_r *.
+begin data.
+15  0 0 0 
+ 1  1 1 1 
+ 2  1 1 2 
+ 1  1 2 1 
+ 1  1 2 2 
+ 1  2 1 1 
+ 4  2 2 1 
+ 2  2 2 2 
+end data.
+
+weight by w.
+
+crosstabs
+       /tables=l96_r by l99_r by l102_r
+       /format=avalue table pivot
+       /statistics=none
+       /cell=count.
+])
+
+AT_CHECK([pspp -O format=html foo.sps], [0], [ignore])
+
+AT_CLEANUP
\ No newline at end of file