Avoid zero division in setupPageState() function;

properly initialize array in PSDataBW().
This commit is contained in:
Andrey Kiselev 2004-08-25 13:14:18 +00:00
parent 9b6b3ab080
commit 0abad54ad0

View File

@ -1,4 +1,4 @@
/* $Id: tiff2ps.c,v 1.24 2004-08-23 13:16:54 dron Exp $ */ /* $Id: tiff2ps.c,v 1.25 2004-08-25 13:14:18 dron Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -24,6 +24,8 @@
* OF THIS SOFTWARE. * OF THIS SOFTWARE.
*/ */
#include "tif_config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* for atof */ #include <stdlib.h> /* for atof */
#include <math.h> #include <math.h>
@ -32,6 +34,12 @@
#include "tiffio.h" #include "tiffio.h"
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#else
extern int getopt(int, char**, char*);
#endif
/* /*
* Revision history * Revision history
* *
@ -414,9 +422,11 @@ setupPageState(TIFF* tif, uint32* pw, uint32* ph, double* pprw, double* pprh)
/* /*
* Calculate printable area. * Calculate printable area.
*/ */
if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, &xres) || !xres) if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, &xres)
|| fabs(xres) < 0.0000001)
xres = PS_UNIT_SIZE; xres = PS_UNIT_SIZE;
if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, &yres) || !yres) if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, &yres)
|| fabs(yres) < 0.0000001)
yres = PS_UNIT_SIZE; yres = PS_UNIT_SIZE;
switch (res_unit) { switch (res_unit) {
case RESUNIT_CENTIMETER: case RESUNIT_CENTIMETER:
@ -600,7 +610,7 @@ TIFF2PS(FILE* fd, TIFF* tif,
} }
fprintf(fd, fprintf(fd,
"1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n", "1 dict begin /PageSize [ %f %f ] def currentdict end setpagedevice\n",
psw, psh); psw, psh);
fputs( fputs(
"<<\n /Policies <<\n /PageSize 3\n >>\n>> setpagedevice\n", "<<\n /Policies <<\n /PageSize 3\n >>\n>> setpagedevice\n",
fd); fd);
@ -1152,7 +1162,7 @@ int
PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h) PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h)
{ {
uint16 fillorder; uint16 fillorder;
int use_rawdata, tiled_image, breaklen; int use_rawdata, tiled_image, breaklen = 0;
uint32 chunk_no, num_chunks, *bc; uint32 chunk_no, num_chunks, *bc;
unsigned char *buf_data, *cp; unsigned char *buf_data, *cp;
tsize_t chunk_size, byte_count; tsize_t chunk_size, byte_count;
@ -1608,6 +1618,7 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h)
(void) w; (void) h; (void) w; (void) h;
tf_buf = (unsigned char *) _TIFFmalloc(stripsize); tf_buf = (unsigned char *) _TIFFmalloc(stripsize);
memset(tf_buf, 0, stripsize);
if (tf_buf == NULL) { if (tf_buf == NULL) {
TIFFError(filename, "No space for scanline buffer"); TIFFError(filename, "No space for scanline buffer");
return; return;