Fix up potential overflows in size calculations by replacing instances
[pspp] / src / ascii.c
index d98ab67b4ed7212036c07d83bf37c47e7036070b..bd55d0efee9b94905dde4dec4715d7c8065f07c5 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 "error.h"
@@ -32,6 +32,9 @@
 #include "pool.h"
 #include "version.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 /* ASCII driver options: (defaults listed first)
 
    output-file="pspp.list"
@@ -192,14 +195,14 @@ static struct outp_option_info *option_info;
 static int
 ascii_open_global (struct outp_class *this UNUSED)
 {
-  option_info = xmalloc ( sizeof (struct outp_option_info ) ) ;
+  option_info = xmalloc (sizeof *option_info);
   option_info->initial = 0;
   option_info->options = 0;
   return 1;
 }
 
 
-static unsigned char *s=0;
+static char *s;
 static int
 ascii_close_global (struct outp_class *this UNUSED)
 {
@@ -228,7 +231,7 @@ ascii_preopen_driver (struct outp_driver *this)
   
   assert (this->driver_open == 0);
   msg (VM (1), _("ASCII driver initializing as `%s'..."), this->name);
-  this->ext = x = xmalloc (sizeof (struct ascii_driver_ext));
+  this->ext = x = xmalloc (sizeof *x);
   x->char_set = CHS_ASCII;
   x->headers = 1;
   x->page_length = 66;
@@ -713,7 +716,7 @@ ascii_open_page (struct outp_driver *this)
 
   if (x->l > x->lines_cap)
     {
-      x->lines = xrealloc (x->lines, sizeof *x->lines * x->l);
+      x->lines = xnrealloc (x->lines, x->l, sizeof *x->lines);
       for (i = x->lines_cap; i < x->l; i++) 
         {
           struct line *line = &x->lines[i];
@@ -743,8 +746,8 @@ expand_line (struct ascii_driver_ext *x, int i, int l)
   if (l > line->char_cap) 
     {
       line->char_cap = l * 2;
-      line->chars = xrealloc (line->chars,
-                              line->char_cap * sizeof *line->chars); 
+      line->chars = xnrealloc (line->chars,
+                               line->char_cap, sizeof *line->chars); 
     }
   for (j = line->char_cnt; j < l; j++)
     line->chars[j] = ' ';
@@ -1155,8 +1158,8 @@ text_draw (struct outp_driver *this, struct outp_text *t)
 /* ascii_close_page () and support routines. */
 
 #define LINE_BUF_SIZE 1024
-static unsigned char *line_buf;
-static unsigned char *line_p;
+static char *line_buf;
+static char *line_p;
 
 static inline int
 commit_line_buf (struct outp_driver *this)
@@ -1309,7 +1312,7 @@ output_shorts (struct outp_driver *this,
 /* Writes CH into line_buf N times, or to THIS->output if line_buf
    overflows. */
 static inline void
-output_char (struct outp_driver *this, int n, int ch)
+output_char (struct outp_driver *this, int n, char ch)
 {
   if (LINE_BUF_SIZE - (line_p - line_buf) >= n)
     {
@@ -1471,7 +1474,7 @@ output_lines (struct outp_driver *this, int first, int count)
        }
       if (n_passes > 1)
        {
-         unsigned char ch;
+         char ch;
 
          return_carriage (this, n_chars);
          n_chars = 0;
@@ -1535,7 +1538,7 @@ ascii_close_page (struct outp_driver *this)
 
   struct ascii_driver_ext *x = this->ext;
   int nl_len, ff_len, total_len;
-  unsigned char *cp;
+  char *cp;
   int i;
 
   assert (this->driver_open && this->page_open);
@@ -1621,11 +1624,7 @@ ascii_close_page (struct outp_driver *this)
          output_string (this, s, &s[total_len]);
 
   if (line_p != line_buf && !commit_line_buf (this))
-    {
-    free(s);
-    s=0;
     return 0;
-    }
 
   this->page_open = 0;
   return 1;
@@ -1633,22 +1632,15 @@ ascii_close_page (struct outp_driver *this)
 
 
 
-void ascii_chart_initialise(struct outp_class *c UNUSED, 
-                           struct chart *ch UNUSED);
-
-void ascii_chart_finalise(struct outp_class *c UNUSED, 
-                         struct chart *ch UNUSED);
-
-
-void
-ascii_chart_initialise(struct outp_class *c UNUSED, struct chart *ch )
+static void
+ascii_chart_initialise(struct outp_driver *d UNUSED, struct chart *ch )
 {
   msg(MW, _("Charts are unsupported with ascii drivers."));
   ch->lp = 0;
 }
 
-void 
-ascii_chart_finalise(struct outp_class *c UNUSED, struct chart *ch UNUSED)
+static void 
+ascii_chart_finalise(struct outp_driver *d UNUSED, struct chart *ch UNUSED)
 {
   
 }