diff options
Diffstat (limited to 'support/ps2eps/src/C/bbox.c')
-rw-r--r-- | support/ps2eps/src/C/bbox.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/support/ps2eps/src/C/bbox.c b/support/ps2eps/src/C/bbox.c index a11a393b9b..668f7e97ee 100644 --- a/support/ps2eps/src/C/bbox.c +++ b/support/ps2eps/src/C/bbox.c @@ -1,13 +1,13 @@ /********************************************************************/ /** bbox -- calculates Bounding Box of a pbmraw/ppmraw-picture **/ -/** Created: Nov. 1997, revised Feb. 1998, Dec. 1999, June 2009 **/ +/** Created: Nov. 1997, revised 1998, 1999, 2009, 2021 **/ /** Author: Roland Bless <roland -at- bless.de> **/ -/** Copyright (C) 1998-2009 Roland Bless **/ +/** Copyright (C) 1998-2020 Roland Bless **/ /** To compile simply use: **/ /** "cc bbox.c -o bbox" or "make bbox" **/ /********************************************************************/ /* - * $Id: bbox.c,v 1.18 2009-10-13 15:03:49 bless Exp $ + * $Id: bbox.c 146 2021-03-12 20:26:23Z bless $ */ /** @@ -52,10 +52,11 @@ /********************** * global variables * **********************/ -const char *const version= "$Revision: 1.18 $ $Date: 2009-10-13 15:03:49 $"; +const char *const version= "$Rev: 146 $"; const char *const prgname= "bbox"; const double round_precision= 1e-6; +const short int inputlinelength= 1024; unsigned char bitval[8]= { @@ -100,7 +101,7 @@ void readppm_and_calcbb(const char *name, const unsigned char tight) { FILE *inputfile; - char inputline[1024]; + char inputline[inputlinelength]; unsigned char magic_found= 0; int x,y,byte_x,i; const double pt_dpi_dbl= 72.0; @@ -111,7 +112,6 @@ void readppm_and_calcbb(const char *name, *tmpcolumnbytep; unsigned int width,height; /* Image Size */ unsigned int byte_width; - unsigned char stepsize; unsigned char colormax= 0; /* max color value */ unsigned int ui_colormax= 0; /* max color value */ @@ -127,25 +127,27 @@ void readppm_and_calcbb(const char *name, { fprintf(stderr,"%s: ERROR -- could not open file %s\n", prgname, name); - return; + exit(1); } } /** check for magic number **/ do { - fgets(inputline, 1024, inputfile); + if (fgets(inputline, inputlinelength, inputfile) == NULL) { + fprintf(stderr,"%s: ERROR -- unexpected end of file %s\n", prgname, name); + fclose(inputfile); + exit(1); + } #ifdef DEBUG fprintf(stderr,"read:[%s]\n",inputline); #endif if ( strcmp(inputline,"P4\n") == 0 ) { - stepsize= 1; magic_found= 4; } else if ( strcmp(inputline,"P6\n") == 0 ) { - stepsize= 3; magic_found= 6; } } @@ -155,12 +157,17 @@ void readppm_and_calcbb(const char *name, { fprintf(stderr,"%s: ERROR -- %s is not in ppmraw or pbmraw format\n", prgname, name); - return; + fclose(inputfile); + exit(1); } /** skip comments **/ do { - fgets(inputline, 1024, inputfile); + if (fgets(inputline, inputlinelength, inputfile) == NULL) { + fprintf(stderr,"%s: ERROR -- unexpected end of file %s\n", prgname, name); + fclose(inputfile); + exit(1); + } #ifdef DEBUG fprintf(stderr,"read:[%s]\n",inputline); #endif @@ -174,8 +181,12 @@ void readppm_and_calcbb(const char *name, sscanf(inputline,"%u %u",&width,&height); if ( magic_found == 6 ) /* PPM file has maximum color-component value */ { - fgets(inputline, 1024, inputfile); - sscanf(inputline,"%u",&ui_colormax); + if (fgets(inputline, inputlinelength, inputfile) == NULL) { + fprintf(stderr,"%s: ERROR -- unexpected end of file %s\n", prgname, name); + fclose(inputfile); + exit(1); + } + sscanf(inputline,"%u",&ui_colormax); colormax = (unsigned char) ui_colormax; /* this is safer */ } #ifdef DEBUG @@ -348,7 +359,7 @@ void readppm_and_calcbb(const char *name, /* skip the rest of the file if any data is still present */ while ( !feof(inputfile) ) { - fgets(inputline, 1024, inputfile); + fgets(inputline, inputlinelength, inputfile); } /* give out Bounding Box */ @@ -356,7 +367,7 @@ void readppm_and_calcbb(const char *name, printf("%%%%HiResBoundingBox: %f %f %f %f\n", hllx, hlly, hurx, hury); } else - fprintf(stderr,"%s: ERROR -- not enough memory to read in one row of the picture\n",prgname); + fprintf(stderr,"%s: ERROR -- not enough memory to read in one row of the picture\n", prgname); fclose(inputfile); free(image_row); |