From fa1e2f50efc0b7b8a9436b40568eadf03feae9dc Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 24 Mar 2017 17:40:39 +0100 Subject: [PATCH] Html Driver: Fix bug when rendering small cells. This fix avoids a bug where the driver would enter a tight loop when rendering cells with zero height or width. --- NEWS | 3 +++ src/output/html.c | 10 ++++++---- tests/automake.mk | 1 + tests/output/html.at | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/output/html.at diff --git a/NEWS b/NEWS index 5085b1fac0..141723b71f 100644 --- 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. diff --git a/src/output/html.c b/src/output/html.c index 8b16ffa780..fd6d40d106 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -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]), " ", "
"); } } + + 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 or tag. */ is_header = (y < table_ht (t) @@ -570,6 +571,7 @@ html_output_table (struct html_driver *html, const struct table_item *item) /* Output or . */ fprintf (html->file, "\n", tag); + next_1: x = cell.d[TABLE_HORZ][1]; table_cell_free (&cell); } diff --git a/tests/automake.mk b/tests/automake.mk index 0fe8a5f69c..93b19d82d0 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -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 index 0000000000..9a048caadf --- /dev/null +++ b/tests/output/html.at @@ -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 -- 2.30.2