Fix up potential overflows in size calculations by replacing instances
[pspp] / src / plot-chart.c
index 795e3113a8da141d428c8a832194557ef47cf8fd..bfe38c8192f105da9453c6dc7c7b5f79296568f5 100644 (file)
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include <stdio.h>
@@ -52,24 +52,23 @@ struct chart *
 chart_create(void)
 {
   struct chart *chart;
-
   struct outp_driver *d;
 
-  chart = xmalloc(sizeof(struct chart) );
-
-  for (d = outp_drivers (NULL); d; d = outp_drivers (d))
+  d = outp_drivers (NULL);
+  if (d == NULL)
+    return NULL;
+  
+  chart = xmalloc (sizeof *chart);
+  d->class->initialise_chart(d, chart);
+  if (!chart->lp) 
     {
-      assert(d->class->initialise_chart);
-      d->class->initialise_chart(d, chart);
-      break; /* KLUDGE!! */
+      free (chart);
+      return NULL; 
     }
 
-  if ( ! chart->lp ) 
-    return 0;
-
   if (pl_openpl_r (chart->lp) < 0)      /* open Plotter */
-      return 0;
-
+    return NULL;
+  
   pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
   pl_flinewidth_r (chart->lp, 0.25);    /* set line thickness */
   pl_pencolorname_r (chart->lp, "black"); 
@@ -77,8 +76,6 @@ chart_create(void)
   pl_erase_r (chart->lp);               /* erase graphics display */
   pl_filltype_r(chart->lp,0);
 
-
-
   pl_savestate_r(chart->lp);
 
   /* Set default chartetry */
@@ -94,7 +91,6 @@ chart_create(void)
   chart->font_size = 0;
   strcpy(chart->fill_colour,"red");
 
-
   /* Get default font size */
   if ( !chart->font_size) 
     chart->font_size = pl_fontsize_r(chart->lp, -1);
@@ -105,11 +101,8 @@ chart_create(void)
           chart->data_right, chart->data_top);
 
   return chart;
-
 }
 
-
-
 /* Draw a tick mark at position
    If label is non zero, then print it at the tick mark
 */
@@ -166,7 +159,8 @@ chart_write_title(struct chart *chart, const char *title, ...)
   va_list ap;
   char buf[100];
 
-  assert(chart);
+  if ( ! chart ) 
+         return ;
 
   pl_savestate_r(chart->lp);
   pl_ffontsize_r(chart->lp,chart->font_size * 1.5);
@@ -187,8 +181,10 @@ void
 chart_submit(struct chart *chart)
 {
   struct som_entity s;
+  struct outp_driver *d;
 
-  assert(chart);
+  if ( ! chart ) 
+     return ;
 
   pl_restorestate_r(chart->lp);
 
@@ -206,8 +202,9 @@ chart_submit(struct chart *chart)
 
   pl_deleteplparams(chart->pl_params);
 
+  d = outp_drivers (NULL);
+  d->class->finalise_chart(d, chart);
   free(chart);
-
 }
 
 
@@ -249,8 +246,8 @@ chart_write_yscale(struct chart *ch, double smin, double smax, int ticks)
     chart_rounded_tick( (smax - smin) / (double) ticks);
 
 
-  assert (ch) ;
-
+  if ( !ch ) 
+         return;
 
   ch->y_max = ceil  ( smax / tick_interval ) * tick_interval ; 
   ch->y_min = floor ( smin / tick_interval ) * tick_interval ;