From df169fb12115ce385cf5b8e09c11a6d728b995b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=98=C3=ADdk=C3=BD?= Date: Mon, 6 Jan 2020 09:52:20 +0100 Subject: [PATCH] Update security code patch --- netpbm-security-code.patch | 1762 +++++++++++++++++++----------------- 1 file changed, 921 insertions(+), 841 deletions(-) diff --git a/netpbm-security-code.patch b/netpbm-security-code.patch index 51ef43e..b225f70 100644 --- a/netpbm-security-code.patch +++ b/netpbm-security-code.patch @@ -1,6 +1,7 @@ -diff -urNp a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c ---- a/analyzer/pgmtexture.c 2019-12-06 09:04:58.779176370 +0100 -+++ b/analyzer/pgmtexture.c 2019-12-06 08:38:15.080037633 +0100 +diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c +index 5883327..eb8cf70 100644 +--- a/analyzer/pgmtexture.c ++++ b/analyzer/pgmtexture.c @@ -98,6 +98,8 @@ vector(unsigned int const nl, assert(nh >= nl); @@ -26,9 +27,10 @@ diff -urNp a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c /* allocate rows and set pointers to them */ for (i = nrl; i <= nrh; ++i) { MALLOCARRAY(m[i], (unsigned) (nch - ncl + 1)); -diff -urNp a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c ---- a/converter/other/gemtopnm.c 2019-12-06 09:04:58.749176101 +0100 -+++ b/converter/other/gemtopnm.c 2019-12-06 08:38:15.081037642 +0100 +diff --git a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c +index d862213..5f1a51a 100644 +--- a/converter/other/gemtopnm.c ++++ b/converter/other/gemtopnm.c @@ -36,7 +36,7 @@ * read 4-plane color IMG files. Therefore changed from PBM to PPM. * Bryan changed it further to use the PNM facilities so it outputs @@ -90,13 +92,6 @@ diff -urNp a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c - pm_usage (usage); - ++argn; - } -- -- if (argc == argn) -- f = stdin; -- else { -- f = pm_openr (argv[argn]); -- ++argn; -- } + while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') + { + if (pm_keymatch(argv[1], "-debug", 2)) @@ -105,7 +100,13 @@ diff -urNp a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c + pm_usage (usage); + ++argn; + } -+ + +- if (argc == argn) +- f = stdin; +- else { +- f = pm_openr (argv[argn]); +- ++argn; +- } + if (argc == argn) + f = stdin; + else { @@ -339,16 +340,17 @@ diff -urNp a/converter/other/gemtopnm.c b/converter/other/gemtopnm.c } -@@ -303,5 +304,3 @@ getinit (file, colsP, rowsP, padrightP, +@@ -303,5 +304,3 @@ getinit (file, colsP, rowsP, padrightP, patlenP, planesP) } } - - -diff -urNp a/converter/other/jpegtopnm.c b/converter/other/jpegtopnm.c ---- a/converter/other/jpegtopnm.c 2019-12-06 09:04:58.748176092 +0100 -+++ b/converter/other/jpegtopnm.c 2019-12-06 08:38:15.082037651 +0100 -@@ -862,6 +862,8 @@ convertImage(FILE * +diff --git a/converter/other/jpegtopnm.c b/converter/other/jpegtopnm.c +index 98552c0..311298c 100644 +--- a/converter/other/jpegtopnm.c ++++ b/converter/other/jpegtopnm.c +@@ -862,6 +862,8 @@ convertImage(FILE * const ofP, /* Calculate output image dimensions so we can allocate space */ jpeg_calc_output_dimensions(cinfoP); @@ -357,9 +359,10 @@ diff -urNp a/converter/other/jpegtopnm.c b/converter/other/jpegtopnm.c /* Start decompressor */ jpeg_start_decompress(cinfoP); -diff -urNp a/converter/other/pbmtopgm.c b/converter/other/pbmtopgm.c ---- a/converter/other/pbmtopgm.c 2019-12-06 09:04:58.746176074 +0100 -+++ b/converter/other/pbmtopgm.c 2019-12-06 08:38:15.082037651 +0100 +diff --git a/converter/other/pbmtopgm.c b/converter/other/pbmtopgm.c +index 69b20fb..382a487 100644 +--- a/converter/other/pbmtopgm.c ++++ b/converter/other/pbmtopgm.c @@ -47,6 +47,7 @@ main(int argc, char *argv[]) { "than the image height (%u rows)", height, rows); @@ -368,9 +371,10 @@ diff -urNp a/converter/other/pbmtopgm.c b/converter/other/pbmtopgm.c maxval = MIN(PGM_OVERALLMAXVAL, width*height); pgm_writepgminit(stdout, cols, rows, maxval, 0) ; -diff -urNp a/converter/other/pnmtoddif.c b/converter/other/pnmtoddif.c ---- a/converter/other/pnmtoddif.c 2019-12-06 09:04:58.747176083 +0100 -+++ b/converter/other/pnmtoddif.c 2019-12-06 08:38:15.083037661 +0100 +diff --git a/converter/other/pnmtoddif.c b/converter/other/pnmtoddif.c +index ac02e42..a2f045b 100644 +--- a/converter/other/pnmtoddif.c ++++ b/converter/other/pnmtoddif.c @@ -629,6 +629,7 @@ main(int argc, char *argv[]) { switch (PNM_FORMAT_TYPE(format)) { case PBM_TYPE: @@ -387,10 +391,11 @@ diff -urNp a/converter/other/pnmtoddif.c b/converter/other/pnmtoddif.c ip.bytes_per_line = 3 * cols; ip.bits_per_pixel = 24; ip.spectral = 5; -diff -urNp a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c ---- a/converter/other/pnmtojpeg.c 2019-12-06 09:04:58.750176110 +0100 -+++ b/converter/other/pnmtojpeg.c 2019-12-06 08:38:15.084037670 +0100 -@@ -606,7 +606,11 @@ read_scan_script(j_compress_ptr const ci +diff --git a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c +index 4482624..757d08d 100644 +--- a/converter/other/pnmtojpeg.c ++++ b/converter/other/pnmtojpeg.c +@@ -606,7 +606,11 @@ read_scan_script(j_compress_ptr const cinfo, want JPOOL_PERMANENT. */ const unsigned int scan_info_size = nscans * sizeof(jpeg_scan_info); @@ -403,7 +408,7 @@ diff -urNp a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c (jpeg_scan_info *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, scan_info_size); -@@ -938,6 +942,8 @@ compute_rescaling_array(JSAMPLE ** const +@@ -938,6 +942,8 @@ compute_rescaling_array(JSAMPLE ** const rescale_p, const pixval maxval, const long half_maxval = maxval / 2; long val; @@ -412,7 +417,7 @@ diff -urNp a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c *rescale_p = (JSAMPLE *) (cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_IMAGE, (size_t) (((long) maxval + 1L) * -@@ -1016,6 +1022,7 @@ convert_scanlines(struct jpeg_compress_s +@@ -1016,6 +1022,7 @@ convert_scanlines(struct jpeg_compress_struct * const cinfo_p, */ /* Allocate the libpnm output and compressor input buffers */ @@ -420,10 +425,11 @@ diff -urNp a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c buffer = (*cinfo_p->mem->alloc_sarray) ((j_common_ptr) cinfo_p, JPOOL_IMAGE, (unsigned int) cinfo_p->image_width * cinfo_p->input_components, -diff -urNp a/converter/other/pnmtops.c b/converter/other/pnmtops.c ---- a/converter/other/pnmtops.c 2019-12-06 09:04:58.750176110 +0100 -+++ b/converter/other/pnmtops.c 2019-12-06 08:38:15.085037679 +0100 -@@ -294,17 +294,21 @@ parseCommandLine(int argc, const char ** +diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c +index de0dfd8..09c28d5 100644 +--- a/converter/other/pnmtops.c ++++ b/converter/other/pnmtops.c +@@ -294,17 +294,21 @@ parseCommandLine(int argc, const char ** argv, validateCompDimension(width, 72, "-width value"); validateCompDimension(height, 72, "-height value"); @@ -446,9 +452,10 @@ diff -urNp a/converter/other/pnmtops.c b/converter/other/pnmtops.c cmdlineP->imageheight = imageheight * 72; } else -diff -urNp a/converter/other/rletopnm.c b/converter/other/rletopnm.c ---- a/converter/other/rletopnm.c 2019-12-06 09:04:58.749176101 +0100 -+++ b/converter/other/rletopnm.c 2019-12-06 08:38:15.086037688 +0100 +diff --git a/converter/other/rletopnm.c b/converter/other/rletopnm.c +index 97f271d..72b63d3 100644 +--- a/converter/other/rletopnm.c ++++ b/converter/other/rletopnm.c @@ -19,6 +19,8 @@ * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, @@ -458,9 +465,10 @@ diff -urNp a/converter/other/rletopnm.c b/converter/other/rletopnm.c */ /* * rletopnm - A conversion program to convert from Utah's "rle" image format -diff -urNp a/converter/other/sirtopnm.c b/converter/other/sirtopnm.c ---- a/converter/other/sirtopnm.c 2019-12-06 09:04:58.748176092 +0100 -+++ b/converter/other/sirtopnm.c 2019-12-06 08:38:15.086037688 +0100 +diff --git a/converter/other/sirtopnm.c b/converter/other/sirtopnm.c +index fafcc91..9fe49d0 100644 +--- a/converter/other/sirtopnm.c ++++ b/converter/other/sirtopnm.c @@ -69,6 +69,7 @@ char* argv[]; } break; @@ -469,10 +477,11 @@ diff -urNp a/converter/other/sirtopnm.c b/converter/other/sirtopnm.c picsize = cols * rows * 3; planesize = cols * rows; if ( !( sirarray = (unsigned char*) malloc( picsize ) ) ) -diff -urNp a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c ---- a/converter/other/tifftopnm.c 2019-12-06 09:04:58.748176092 +0100 -+++ b/converter/other/tifftopnm.c 2019-12-06 08:38:15.087037697 +0100 -@@ -1372,7 +1372,9 @@ convertRasterByRows(pnmOut * const +diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c +index c1e7af8..ef9253b 100644 +--- a/converter/other/tifftopnm.c ++++ b/converter/other/tifftopnm.c +@@ -1372,7 +1372,9 @@ convertRasterByRows(pnmOut * const pnmOutP, if (scanbuf == NULL) pm_error("can't allocate memory for scanline buffer"); @@ -483,10 +492,11 @@ diff -urNp a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c if (samplebuf == NULL) pm_error("can't allocate memory for row buffer"); -diff -urNp a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c ---- a/converter/other/xwdtopnm.c 2019-12-06 09:04:58.747176083 +0100 -+++ b/converter/other/xwdtopnm.c 2019-12-06 08:38:15.088037706 +0100 -@@ -210,6 +210,10 @@ processX10Header(X10WDFileHeader * cons +diff --git a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c +index df3c737..6c19ade 100644 +--- a/converter/other/xwdtopnm.c ++++ b/converter/other/xwdtopnm.c +@@ -210,6 +210,10 @@ processX10Header(X10WDFileHeader * const h10P, *colorsP = pnm_allocrow(2); PNM_ASSIGN1((*colorsP)[0], 0); PNM_ASSIGN1((*colorsP)[1], *maxvalP); @@ -497,7 +507,7 @@ diff -urNp a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c *padrightP = (((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width) * 8; *bits_per_itemP = 16; -@@ -635,6 +639,7 @@ processX11Header(X11WDFileHeader * cons +@@ -635,6 +639,7 @@ processX11Header(X11WDFileHeader * const h11P, *colsP = h11FixedP->pixmap_width; *rowsP = h11FixedP->pixmap_height; @@ -505,9 +515,10 @@ diff -urNp a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c *padrightP = h11FixedP->bytes_per_line * 8 - h11FixedP->pixmap_width * h11FixedP->bits_per_pixel; -diff -urNp a/converter/pbm/mdatopbm.c b/converter/pbm/mdatopbm.c ---- a/converter/pbm/mdatopbm.c 2019-12-06 09:04:58.742176038 +0100 -+++ b/converter/pbm/mdatopbm.c 2019-12-06 08:38:15.088037706 +0100 +diff --git a/converter/pbm/mdatopbm.c b/converter/pbm/mdatopbm.c +index d8e0657..12c7468 100644 +--- a/converter/pbm/mdatopbm.c ++++ b/converter/pbm/mdatopbm.c @@ -245,10 +245,13 @@ main(int argc, char **argv) { pm_readlittleshort(infile, &yy); nInCols = yy; } @@ -523,9 +534,10 @@ diff -urNp a/converter/pbm/mdatopbm.c b/converter/pbm/mdatopbm.c data = pbm_allocarray(nOutCols, nOutRows); -diff -urNp a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c ---- a/converter/pbm/mgrtopbm.c 2019-12-06 09:04:58.743176047 +0100 -+++ b/converter/pbm/mgrtopbm.c 2019-12-06 08:38:15.088037706 +0100 +diff --git a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c +index 9f7004a..60e8477 100644 +--- a/converter/pbm/mgrtopbm.c ++++ b/converter/pbm/mgrtopbm.c @@ -65,6 +65,8 @@ readMgrHeader(FILE * const ifP, if (head.h_high < ' ' || head.l_high < ' ') pm_error("Invalid width field in MGR header"); @@ -535,9 +547,31 @@ diff -urNp a/converter/pbm/mgrtopbm.c b/converter/pbm/mgrtopbm.c *colsP = (((int)head.h_wide - ' ') << 6) + ((int)head.l_wide - ' '); *rowsP = (((int)head.h_high - ' ') << 6) + ((int) head.l_high - ' '); *padrightP = ( ( *colsP + pad - 1 ) / pad ) * pad - *colsP; -diff -urNp a/converter/pbm/pbmtogem.c b/converter/pbm/pbmtogem.c ---- a/converter/pbm/pbmtogem.c 2019-12-06 09:04:58.743176047 +0100 -+++ b/converter/pbm/pbmtogem.c 2019-12-06 08:38:15.089037715 +0100 +diff --git a/converter/pbm/pbmto4425.c b/converter/pbm/pbmto4425.c +index 1d97ac6..c4c8cbb 100644 +--- a/converter/pbm/pbmto4425.c ++++ b/converter/pbm/pbmto4425.c +@@ -2,6 +2,7 @@ + + #include "nstring.h" + #include "pbm.h" ++#include + + static char bit_table[2][3] = { + {1, 4, 0x10}, +@@ -160,7 +161,7 @@ main(int argc, char * argv[]) { + xres = vmap_width * 2; + yres = vmap_height * 3; + +- vmap = malloc(vmap_width * vmap_height * sizeof(char)); ++ vmap = malloc3(vmap_width, vmap_height, sizeof(char)); + if(vmap == NULL) + { + pm_error( "Cannot allocate memory" ); +diff --git a/converter/pbm/pbmtogem.c b/converter/pbm/pbmtogem.c +index 9eab041..13b0257 100644 +--- a/converter/pbm/pbmtogem.c ++++ b/converter/pbm/pbmtogem.c @@ -79,6 +79,7 @@ putinit (int const rows, int const cols) bitsperitem = 0; bitshift = 7; @@ -546,9 +580,10 @@ diff -urNp a/converter/pbm/pbmtogem.c b/converter/pbm/pbmtogem.c outmax = (cols + 7) / 8; outrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char)); lastrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char)); -diff -urNp a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c ---- a/converter/pbm/pbmtogo.c 2019-12-06 09:04:58.742176038 +0100 -+++ b/converter/pbm/pbmtogo.c 2019-12-06 08:38:15.089037715 +0100 +diff --git a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c +index 23b2ee9..d2ee91f 100644 +--- a/converter/pbm/pbmtogo.c ++++ b/converter/pbm/pbmtogo.c @@ -158,6 +158,7 @@ main(int argc, bitrow = pbm_allocrow(cols); @@ -557,9 +592,10 @@ diff -urNp a/converter/pbm/pbmtogo.c b/converter/pbm/pbmtogo.c rucols = ( cols + 7 ) / 8; bytesperrow = rucols; /* GraphOn uses bytes */ rucols = rucols * 8; -diff -urNp a/converter/pbm/pbmtolj.c b/converter/pbm/pbmtolj.c ---- a/converter/pbm/pbmtolj.c 2019-12-06 09:04:58.743176047 +0100 -+++ b/converter/pbm/pbmtolj.c 2019-12-06 08:38:15.090037725 +0100 +diff --git a/converter/pbm/pbmtolj.c b/converter/pbm/pbmtolj.c +index 3cd7670..0b51932 100644 +--- a/converter/pbm/pbmtolj.c ++++ b/converter/pbm/pbmtolj.c @@ -120,7 +120,11 @@ parseCommandLine(int argc, char ** argv, static void allocateBuffers(unsigned int const cols) { @@ -572,9 +608,10 @@ diff -urNp a/converter/pbm/pbmtolj.c b/converter/pbm/pbmtolj.c packBufferSize = rowBufferSize + (rowBufferSize + 127) / 128 + 1; deltaBufferSize = rowBufferSize + rowBufferSize / 8 + 10; -diff -urNp a/converter/pbm/pbmtomda.c b/converter/pbm/pbmtomda.c ---- a/converter/pbm/pbmtomda.c 2019-12-06 09:04:58.742176038 +0100 -+++ b/converter/pbm/pbmtomda.c 2019-12-06 08:38:15.091037734 +0100 +diff --git a/converter/pbm/pbmtomda.c b/converter/pbm/pbmtomda.c +index 3ad5149..9efe5cf 100644 +--- a/converter/pbm/pbmtomda.c ++++ b/converter/pbm/pbmtomda.c @@ -179,6 +179,7 @@ int main(int argc, char **argv) nOutRowsUnrounded = bScale ? nInRows/2 : nInRows; @@ -583,9 +620,10 @@ diff -urNp a/converter/pbm/pbmtomda.c b/converter/pbm/pbmtomda.c nOutRows = ((nOutRowsUnrounded + 3) / 4) * 4; /* MDA wants rows a multiple of 4 */ nOutCols = nInCols / 8; -diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c ---- a/converter/pbm/pbmtoppa/pbm.c 2019-12-06 09:04:58.745176065 +0100 -+++ b/converter/pbm/pbmtoppa/pbm.c 2019-12-06 08:38:15.091037734 +0100 +diff --git a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c +index ae36e0d..1c8d236 100644 +--- a/converter/pbm/pbmtoppa/pbm.c ++++ b/converter/pbm/pbmtoppa/pbm.c @@ -11,185 +11,128 @@ #include #include @@ -659,35 +697,18 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c - } - return retval; -} -- +int make_pbm_stat(pbm_stat* pbm,FILE* fptr) +{ + char line[1024]; -+ + + pbm->fptr=fptr; + pbm->version=none; + pbm->current_line=0; + pbm->unread = 0; -+ + + if (fgets (line, 1024, fptr) == NULL) + return 0; + line[strlen(line)-1] = 0; -+ -+ if(!strcmp(line,"P1")) pbm->version=P1; -+ if(!strcmp(line,"P4")) pbm->version=P4; -+ if(pbm->version == none) -+ { -+ fprintf(stderr,"pbm_readheader(): unknown PBM magic '%s'\n",line); -+ return 0; -+ } -+ -+ do -+ if (fgets (line, 1024, fptr) == NULL) -+ return 0; -+ while (line[0] == '#'); - -+ if (2 != sscanf (line, "%d %d", &pbm->width, &pbm->height)) -+ return 0; -static int -getbytes(FILE * const ifP, @@ -726,11 +747,23 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c - retval = 1; - } - return retval; -+ return 1; - } +-} ++ if(!strcmp(line,"P1")) pbm->version=P1; ++ if(!strcmp(line,"P4")) pbm->version=P4; ++ if(pbm->version == none) ++ { ++ fprintf(stderr,"pbm_readheader(): unknown PBM magic '%s'\n",line); ++ return 0; ++ } + ++ do ++ if (fgets (line, 1024, fptr) == NULL) ++ return 0; ++ while (line[0] == '#'); + ++ if (2 != sscanf (line, "%d %d", &pbm->width, &pbm->height)) ++ return 0; -- -- -int -pbm_readline(pbm_stat * const pbmStatP, - unsigned char * const data) { @@ -777,6 +810,11 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c - retval = 0; - } - } +- } +- return retval; ++ return 1; + } + +static int getbytes(FILE *fptr,int width,unsigned char* data) +{ + unsigned char mask,acc,*place; @@ -801,13 +839,12 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c + acc=0; + mask=0x80; + } - } -- return retval; ++ } + } + if(width%8) + *place=acc; + return 1; - } ++} +/* Reads a single line into data which must be at least (pbm->width+7)/8 + bytes of storage */ @@ -827,16 +864,6 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c + return 1; + } -+ switch(pbm->version) -+ { -+ case P1: -+ if(getbytes(pbm->fptr,pbm->width,data)) -+ { -+ pbm->current_line++; -+ return 1; -+ } -+ return 0; - -void -pbm_unreadline(pbm_stat * const pbmStatP, - void * const data) { @@ -850,6 +877,17 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c - pbmStatP->revdata = malloc ((pbmStatP->width+7)/8); - memcpy(pbmStatP->revdata, data, (pbmStatP->width+7)/8); - --pbmStatP->current_line; ++ switch(pbm->version) ++ { ++ case P1: ++ if(getbytes(pbm->fptr,pbm->width,data)) ++ { ++ pbm->current_line++; ++ return 1; + } +-} ++ return 0; ++ + case P4: + overflow_add(pbm->width, 7); + tmp=(pbm->width+7)/8; @@ -858,8 +896,7 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c + { + pbm->current_line++; + return 1; - } --} ++ } + fprintf(stderr,"pbm_readline(): error reading line data (%d)\n",tmp2); + return 0; @@ -882,9 +919,10 @@ diff -urNp a/converter/pbm/pbmtoppa/pbm.c b/converter/pbm/pbmtoppa/pbm.c + memcpy (pbm->revdata, data, (pbm->width+7)/8); + pbm->current_line--; +} -diff -urNp a/converter/pbm/pbmtoppa/pbmtoppa.c b/converter/pbm/pbmtoppa/pbmtoppa.c ---- a/converter/pbm/pbmtoppa/pbmtoppa.c 2019-12-06 09:04:58.745176065 +0100 -+++ b/converter/pbm/pbmtoppa/pbmtoppa.c 2019-12-06 08:38:15.092037743 +0100 +diff --git a/converter/pbm/pbmtoppa/pbmtoppa.c b/converter/pbm/pbmtoppa/pbmtoppa.c +index ff4a599..aa510ec 100644 +--- a/converter/pbm/pbmtoppa/pbmtoppa.c ++++ b/converter/pbm/pbmtoppa/pbmtoppa.c @@ -453,6 +453,7 @@ main(int argc, char *argv[]) { pm_error("main(): unrecognized parameter '%s'", argv[argn]); } @@ -893,9 +931,10 @@ diff -urNp a/converter/pbm/pbmtoppa/pbmtoppa.c b/converter/pbm/pbmtoppa/pbmtoppa Pwidth=(Width+7)/8; printer.fptr=out; -diff -urNp a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c ---- a/converter/pbm/pbmtoxbm.c 2019-12-06 09:04:58.744176056 +0100 -+++ b/converter/pbm/pbmtoxbm.c 2019-12-06 08:38:15.092037743 +0100 +diff --git a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c +index ecb72b3..fc0eb9c 100644 +--- a/converter/pbm/pbmtoxbm.c ++++ b/converter/pbm/pbmtoxbm.c @@ -352,6 +352,8 @@ convertRaster(FILE * const ifP, unsigned char * bitrow; @@ -905,29 +944,10 @@ diff -urNp a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c putinit(xbmVersion); -diff -urNp a/converter/pbm/pbmto4425.c b/converter/pbm/pbmto4425.c ---- a/converter/pbm/pbmto4425.c 2019-12-06 09:04:58.742176038 +0100 -+++ b/converter/pbm/pbmto4425.c 2019-12-06 08:38:15.089037715 +0100 -@@ -2,6 +2,7 @@ - - #include "nstring.h" - #include "pbm.h" -+#include - - static char bit_table[2][3] = { - {1, 4, 0x10}, -@@ -160,7 +161,7 @@ main(int argc, char * argv[]) { - xres = vmap_width * 2; - yres = vmap_height * 3; - -- vmap = malloc(vmap_width * vmap_height * sizeof(char)); -+ vmap = malloc3(vmap_width, vmap_height, sizeof(char)); - if(vmap == NULL) - { - pm_error( "Cannot allocate memory" ); -diff -urNp a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c ---- a/converter/pbm/pktopbm.c 2019-12-06 09:04:58.744176056 +0100 -+++ b/converter/pbm/pktopbm.c 2019-12-06 08:38:15.093037752 +0100 +diff --git a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c +index 712f339..b6fcb02 100644 +--- a/converter/pbm/pktopbm.c ++++ b/converter/pbm/pktopbm.c @@ -280,6 +280,7 @@ main(int argc, char *argv[]) { if (flagbyte == 7) { /* long form preamble */ integer packetlength = get32() ; /* character packet length */ @@ -936,9 +956,10 @@ diff -urNp a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c endofpacket = packetlength + pktopbm_pkloc; /* calculate end of packet */ if ((car >= MAXPKCHAR) || !filename[car]) { -diff -urNp a/converter/pbm/thinkjettopbm.l b/converter/pbm/thinkjettopbm.l ---- a/converter/pbm/thinkjettopbm.l 2019-12-06 09:04:58.743176047 +0100 -+++ b/converter/pbm/thinkjettopbm.l 2019-12-06 08:38:15.093037752 +0100 +diff --git a/converter/pbm/thinkjettopbm.l b/converter/pbm/thinkjettopbm.l +index 5de4f2b..7f31de5 100644 +--- a/converter/pbm/thinkjettopbm.l ++++ b/converter/pbm/thinkjettopbm.l @@ -114,7 +114,9 @@ DIG [0-9] \033\*b{DIG}+W { int l; @@ -959,9 +980,10 @@ diff -urNp a/converter/pbm/thinkjettopbm.l b/converter/pbm/thinkjettopbm.l pbm_writepbminit(stdout, maxRowLength*8, rowCount, 0); packed_bitrow = malloc(maxRowLength); -diff -urNp a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c ---- a/converter/pbm/ybmtopbm.c 2019-12-06 09:04:58.742176038 +0100 -+++ b/converter/pbm/ybmtopbm.c 2019-12-06 08:38:15.093037752 +0100 +diff --git a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c +index 2a42908..cf1ff03 100644 +--- a/converter/pbm/ybmtopbm.c ++++ b/converter/pbm/ybmtopbm.c @@ -43,6 +43,7 @@ getinit(FILE * const ifP, pm_error("EOF / read error"); @@ -970,9 +992,10 @@ diff -urNp a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c } -diff -urNp a/converter/pgm/lispmtopgm.c b/converter/pgm/lispmtopgm.c ---- a/converter/pgm/lispmtopgm.c 2019-12-06 09:04:58.746176074 +0100 -+++ b/converter/pgm/lispmtopgm.c 2019-12-06 08:38:15.094037761 +0100 +diff --git a/converter/pgm/lispmtopgm.c b/converter/pgm/lispmtopgm.c +index 40dd3fb..b5469f7 100644 +--- a/converter/pgm/lispmtopgm.c ++++ b/converter/pgm/lispmtopgm.c @@ -58,6 +58,7 @@ main( argc, argv ) pm_error( "depth (%d bits) is too large", depth); @@ -981,7 +1004,7 @@ diff -urNp a/converter/pgm/lispmtopgm.c b/converter/pgm/lispmtopgm.c grayrow = pgm_allocrow( ( cols + 7 ) / 8 * 8 ); for ( row = 0; row < rows; ++row ) -@@ -102,6 +103,8 @@ getinit( file, colsP, rowsP, depthP, pad +@@ -102,6 +103,8 @@ getinit( file, colsP, rowsP, depthP, padrightP ) if ( *depthP == 0 ) *depthP = 1; /* very old file */ @@ -990,9 +1013,10 @@ diff -urNp a/converter/pgm/lispmtopgm.c b/converter/pgm/lispmtopgm.c *padrightP = ( ( *colsP + 31 ) / 32 ) * 32 - *colsP; -diff -urNp a/converter/pgm/psidtopgm.c b/converter/pgm/psidtopgm.c ---- a/converter/pgm/psidtopgm.c 2019-12-06 09:04:58.745176065 +0100 -+++ b/converter/pgm/psidtopgm.c 2019-12-06 08:38:15.094037761 +0100 +diff --git a/converter/pgm/psidtopgm.c b/converter/pgm/psidtopgm.c +index 07417d1..25bb311 100644 +--- a/converter/pgm/psidtopgm.c ++++ b/converter/pgm/psidtopgm.c @@ -78,6 +78,7 @@ main(int argc, pm_error("bits/sample (%d) is too large.", bitspersample); @@ -1001,9 +1025,23 @@ diff -urNp a/converter/pgm/psidtopgm.c b/converter/pgm/psidtopgm.c grayrow = pgm_allocrow((cols + 7) / 8 * 8); for (row = 0; row < rows; ++row) { unsigned int col; -diff -urNp a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c ---- a/converter/ppm/ilbmtoppm.c 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/ilbmtoppm.c 2019-12-06 08:38:15.096037779 +0100 +diff --git a/converter/ppm/Makefile b/converter/ppm/Makefile +index 003ef8d..b97349d 100644 +--- a/converter/ppm/Makefile ++++ b/converter/ppm/Makefile +@@ -11,7 +11,7 @@ SUBDIRS = hpcdtoppm ppmtompeg + + PORTBINARIES = 411toppm eyuvtoppm gouldtoppm ilbmtoppm imgtoppm \ + leaftoppm mtvtoppm neotoppm \ +- pcxtoppm pc1toppm pi1toppm picttoppm pjtoppm \ ++ pcxtoppm pc1toppm pi1toppm pjtoppm \ + ppmtoacad ppmtoapplevol ppmtoarbtxt ppmtoascii \ + ppmtobmp ppmtoeyuv ppmtogif ppmtoicr ppmtoilbm \ + ppmtoleaf ppmtolj ppmtomitsu ppmtoneo \ +diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c +index 92d4d6f..60853dd 100644 +--- a/converter/ppm/ilbmtoppm.c ++++ b/converter/ppm/ilbmtoppm.c @@ -608,6 +608,7 @@ decode_row(FILE * const ifP, rawtype *chp; @@ -1046,7 +1084,7 @@ diff -urNp a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c MALLOCARRAY_NOFAIL(redtable, redmaxval +1); MALLOCARRAY_NOFAIL(greentable, greenmaxval +1); MALLOCARRAY_NOFAIL(bluetable, bluemaxval +1); -@@ -1802,7 +1823,9 @@ PCHG_ConvertSmall(PCHGHeader * const +@@ -1802,7 +1823,9 @@ PCHG_ConvertSmall(PCHGHeader * const pchgP, ChangeCount32 = *data++; remDataSize -= 2; @@ -1074,9 +1112,11 @@ diff -urNp a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c MALLOCARRAY_NOFAIL(ilbmrow, RowBytes(bmhdP->w)); *viewportmodesP |= fakeviewport; /* -isham/-isehb */ -diff -urNp a/converter/ppm/ilbmtoppm.c.rej b/converter/ppm/ilbmtoppm.c.rej ---- a/converter/ppm/ilbmtoppm.c.rej 1970-01-01 01:00:00.000000000 +0100 -+++ b/converter/ppm/ilbmtoppm.c.rej 2019-12-06 08:38:15.096037779 +0100 +diff --git a/converter/ppm/ilbmtoppm.c.rej b/converter/ppm/ilbmtoppm.c.rej +new file mode 100644 +index 0000000..972cad0 +--- /dev/null ++++ b/converter/ppm/ilbmtoppm.c.rej @@ -0,0 +1,46 @@ +--- converter/ppm/ilbmtoppm.c ++++ converter/ppm/ilbmtoppm.c @@ -1124,9 +1164,10 @@ diff -urNp a/converter/ppm/ilbmtoppm.c.rej b/converter/ppm/ilbmtoppm.c.rej + for( i = 0; i < changes; i++ ) { + if( totalchanges >= PCHG->TotalChanges ) goto fail; + if( datasize < 2 ) goto fail; -diff -urNp a/converter/ppm/imgtoppm.c b/converter/ppm/imgtoppm.c ---- a/converter/ppm/imgtoppm.c 2019-12-06 09:04:58.764176235 +0100 -+++ b/converter/ppm/imgtoppm.c 2019-12-06 08:38:15.097037789 +0100 +diff --git a/converter/ppm/imgtoppm.c b/converter/ppm/imgtoppm.c +index 7078b88..eb8509e 100644 +--- a/converter/ppm/imgtoppm.c ++++ b/converter/ppm/imgtoppm.c @@ -84,6 +84,7 @@ main(int argc, char ** argv) { len = atoi((char*) buf ); if ( fread( buf, len, 1, ifp ) != 1 ) @@ -1143,22 +1184,11 @@ diff -urNp a/converter/ppm/imgtoppm.c b/converter/ppm/imgtoppm.c if ( len != cols * rows ) pm_message( "pixel data length (%d) does not match image size (%d)", -diff -urNp a/converter/ppm/Makefile b/converter/ppm/Makefile ---- a/converter/ppm/Makefile 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/Makefile 2019-12-06 08:38:15.095037770 +0100 -@@ -11,7 +11,7 @@ SUBDIRS = hpcdtoppm ppmtompeg - - PORTBINARIES = 411toppm eyuvtoppm gouldtoppm ilbmtoppm imgtoppm \ - leaftoppm mtvtoppm neotoppm \ -- pcxtoppm pc1toppm pi1toppm picttoppm pjtoppm \ -+ pcxtoppm pc1toppm pi1toppm pjtoppm \ - ppmtoacad ppmtoapplevol ppmtoarbtxt ppmtoascii \ - ppmtobmp ppmtoeyuv ppmtogif ppmtoicr ppmtoilbm \ - ppmtoleaf ppmtolj ppmtomitsu ppmtoneo \ -diff -urNp a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c ---- a/converter/ppm/pcxtoppm.c 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/pcxtoppm.c 2019-12-06 08:38:15.097037789 +0100 -@@ -409,6 +409,7 @@ pcx_planes_to_pixels(pixels, bitplanes, +diff --git a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c +index e252ba2..270ae3b 100644 +--- a/converter/ppm/pcxtoppm.c ++++ b/converter/ppm/pcxtoppm.c +@@ -409,6 +409,7 @@ pcx_planes_to_pixels(pixels, bitplanes, bytesperline, planes, bitsperpixel) /* * clear the pixel buffer */ @@ -1174,17 +1204,19 @@ diff -urNp a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c rawcols = BytesPerLine * 8 / BitsPerPixel; if (headerCols > rawcols) { pm_message("warning - BytesPerLine = %d, " -diff -urNp a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c ---- a/converter/ppm/picttoppm.c 2019-12-06 09:04:58.764176235 +0100 -+++ b/converter/ppm/picttoppm.c 2019-12-06 08:38:15.099037807 +0100 +diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c +index b8fb864..177bc30 100644 +--- a/converter/ppm/picttoppm.c ++++ b/converter/ppm/picttoppm.c @@ -1,3 +1,4 @@ +#error "Unfixable. Don't ship me" /* * picttoppm.c -- convert a MacIntosh PICT file to PPM format. * -diff -urNp a/converter/ppm/pjtoppm.c b/converter/ppm/pjtoppm.c ---- a/converter/ppm/pjtoppm.c 2019-12-06 09:04:58.764176235 +0100 -+++ b/converter/ppm/pjtoppm.c 2019-12-06 08:38:15.100037816 +0100 +diff --git a/converter/ppm/pjtoppm.c b/converter/ppm/pjtoppm.c +index b8b94f7..62ce77e 100644 +--- a/converter/ppm/pjtoppm.c ++++ b/converter/ppm/pjtoppm.c @@ -11,87 +11,65 @@ */ @@ -1515,10 +1547,11 @@ diff -urNp a/converter/ppm/pjtoppm.c b/converter/ppm/pjtoppm.c - - - -diff -urNp a/converter/ppm/ppmtoeyuv.c b/converter/ppm/ppmtoeyuv.c ---- a/converter/ppm/ppmtoeyuv.c 2019-12-06 09:04:58.764176235 +0100 -+++ b/converter/ppm/ppmtoeyuv.c 2019-12-06 08:38:15.100037816 +0100 -@@ -114,6 +114,7 @@ create_multiplication_tables(const pixva +diff --git a/converter/ppm/ppmtoeyuv.c b/converter/ppm/ppmtoeyuv.c +index f5ce115..6f072be 100644 +--- a/converter/ppm/ppmtoeyuv.c ++++ b/converter/ppm/ppmtoeyuv.c +@@ -114,6 +114,7 @@ create_multiplication_tables(const pixval maxval) { int index; @@ -1526,9 +1559,10 @@ diff -urNp a/converter/ppm/ppmtoeyuv.c b/converter/ppm/ppmtoeyuv.c MALLOCARRAY_NOFAIL(mult299 , maxval+1); MALLOCARRAY_NOFAIL(mult587 , maxval+1); MALLOCARRAY_NOFAIL(mult114 , maxval+1); -diff -urNp a/converter/ppm/ppmtolj.c b/converter/ppm/ppmtolj.c ---- a/converter/ppm/ppmtolj.c 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/ppmtolj.c 2019-12-06 08:38:15.101037825 +0100 +diff --git a/converter/ppm/ppmtolj.c b/converter/ppm/ppmtolj.c +index 7ed814e..b4e7db1 100644 +--- a/converter/ppm/ppmtolj.c ++++ b/converter/ppm/ppmtolj.c @@ -182,6 +182,7 @@ int main(int argc, char *argv[]) { ppm_readppminit( ifp, &cols, &rows, &maxval, &format ); pixelrow = ppm_allocrow( cols ); @@ -1537,9 +1571,10 @@ diff -urNp a/converter/ppm/ppmtolj.c b/converter/ppm/ppmtolj.c obuf = (unsigned char *) pm_allocrow(cols * 3, sizeof(unsigned char)); cbuf = (unsigned char *) pm_allocrow(cols * 6, sizeof(unsigned char)); if (mode == C_TRANS_MODE_DELTA) -diff -urNp a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c ---- a/converter/ppm/ppmtomitsu.c 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/ppmtomitsu.c 2019-12-06 08:38:15.101037825 +0100 +diff --git a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c +index 5b0b324..11db755 100644 +--- a/converter/ppm/ppmtomitsu.c ++++ b/converter/ppm/ppmtomitsu.c @@ -685,6 +685,8 @@ main(int argc, char * argv[]) { medias = MSize_User; @@ -1549,10 +1584,11 @@ diff -urNp a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c medias.maxcols *= 2; medias.maxrows *= 2; } -diff -urNp a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c ---- a/converter/ppm/ppmtopcx.c 2019-12-06 09:04:58.765176244 +0100 -+++ b/converter/ppm/ppmtopcx.c 2019-12-06 08:38:15.102037834 +0100 -@@ -425,6 +425,8 @@ ppmTo16ColorPcx(pixel ** cons +diff --git a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c +index fa68edc..97dfb2b 100644 +--- a/converter/ppm/ppmtopcx.c ++++ b/converter/ppm/ppmtopcx.c +@@ -425,6 +425,8 @@ ppmTo16ColorPcx(pixel ** const pixels, else Planes = 1; } } @@ -1561,9 +1597,10 @@ diff -urNp a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c BytesPerLine = ((cols * BitsPerPixel) + 7) / 8; MALLOCARRAY_NOFAIL(indexRow, cols); MALLOCARRAY_NOFAIL(planesrow, BytesPerLine); -diff -urNp a/converter/ppm/ppmtopict.c b/converter/ppm/ppmtopict.c ---- a/converter/ppm/ppmtopict.c 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/ppmtopict.c 2019-12-06 08:38:15.103037843 +0100 +diff --git a/converter/ppm/ppmtopict.c b/converter/ppm/ppmtopict.c +index 36464b6..c91ccf2 100644 +--- a/converter/ppm/ppmtopict.c ++++ b/converter/ppm/ppmtopict.c @@ -450,6 +450,8 @@ main(int argc, const char ** argv) { putShort(stdout, 0); /* mode */ @@ -1573,9 +1610,10 @@ diff -urNp a/converter/ppm/ppmtopict.c b/converter/ppm/ppmtopict.c outBuf = malloc((unsigned)(cols+cols/MAX_COUNT+1)); for (row = 0, oc = 0; row < rows; ++row) { unsigned int rowSize; -diff -urNp a/converter/ppm/ppmtopj.c b/converter/ppm/ppmtopj.c ---- a/converter/ppm/ppmtopj.c 2019-12-06 09:04:58.765176244 +0100 -+++ b/converter/ppm/ppmtopj.c 2019-12-06 08:38:15.103037843 +0100 +diff --git a/converter/ppm/ppmtopj.c b/converter/ppm/ppmtopj.c +index d116773..fc84cac 100644 +--- a/converter/ppm/ppmtopj.c ++++ b/converter/ppm/ppmtopj.c @@ -179,6 +179,7 @@ char *argv[]; pixels = ppm_readppm( ifp, &cols, &rows, &maxval ); @@ -1584,9 +1622,10 @@ diff -urNp a/converter/ppm/ppmtopj.c b/converter/ppm/ppmtopj.c obuf = (unsigned char *) pm_allocrow(cols, sizeof(unsigned char)); cbuf = (unsigned char *) pm_allocrow(cols * 2, sizeof(unsigned char)); -diff -urNp a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c ---- a/converter/ppm/ppmtopjxl.c 2019-12-06 09:04:58.764176235 +0100 -+++ b/converter/ppm/ppmtopjxl.c 2019-12-06 08:38:15.104037853 +0100 +diff --git a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c +index 90bcef0..72d0027 100644 +--- a/converter/ppm/ppmtopjxl.c ++++ b/converter/ppm/ppmtopjxl.c @@ -267,6 +267,9 @@ main(int argc, const char * argv[]) { if (maxval > PCL_MAXVAL) pm_error("color range too large; reduce with ppmcscale"); @@ -1620,9 +1659,10 @@ diff -urNp a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c inrow = (char *)malloc((unsigned)bpp); outrow = (char *)malloc((unsigned)bpp*2); runcnt = (signed char *)malloc((unsigned)bpp); -diff -urNp a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c ---- a/converter/ppm/ppmtowinicon.c 2019-12-06 09:04:58.765176244 +0100 -+++ b/converter/ppm/ppmtowinicon.c 2019-12-06 08:38:15.104037853 +0100 +diff --git a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c +index c673798..af2b445 100644 +--- a/converter/ppm/ppmtowinicon.c ++++ b/converter/ppm/ppmtowinicon.c @@ -12,6 +12,7 @@ #include @@ -1631,7 +1671,7 @@ diff -urNp a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c #include "pm_c_util.h" #include "winico.h" -@@ -214,6 +215,7 @@ createAndBitmap (gray ** const ba, int c +@@ -214,6 +215,7 @@ createAndBitmap (gray ** const ba, int const cols, int const rows, MALLOCARRAY_NOFAIL(rowData, rows); icBitmap->xBytes = xBytes; icBitmap->data = rowData; @@ -1639,7 +1679,7 @@ diff -urNp a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c icBitmap->size = xBytes * rows; for (y=0;yxBytes = xBytes; icBitmap->data = rowData; @@ -1647,7 +1687,7 @@ diff -urNp a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c icBitmap->size = xBytes * rows; for (y=0;yxBytes = xBytes; icBitmap->data = rowData; @@ -1655,7 +1695,7 @@ diff -urNp a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c icBitmap->size = xBytes * rows; for (y=0;ybitcount = bpp; entry->ih = createInfoHeader(entry, xorBitmap, andBitmap); entry->colors = palette->colors; @@ -1668,10 +1708,11 @@ diff -urNp a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count); if (verbose) pm_message("entry->size_in_bytes = %d + %d + %d = %d", -diff -urNp a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c ---- a/converter/ppm/ppmtoxpm.c 2019-12-06 09:04:58.765176244 +0100 -+++ b/converter/ppm/ppmtoxpm.c 2019-12-06 08:38:15.105037862 +0100 -@@ -198,6 +198,7 @@ genNumstr(unsigned int const input, int +diff --git a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c +index 0e31692..1b3923f 100644 +--- a/converter/ppm/ppmtoxpm.c ++++ b/converter/ppm/ppmtoxpm.c +@@ -198,6 +198,7 @@ genNumstr(unsigned int const input, int const digits) { unsigned int i; /* Allocate memory for printed number. Abort if error. */ @@ -1687,9 +1728,10 @@ diff -urNp a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c MALLOCARRAY(cmap, cmapSize); if (cmapP == NULL) pm_error("Out of memory allocating %u bytes for a color map.", -diff -urNp a/converter/ppm/qrttoppm.c b/converter/ppm/qrttoppm.c ---- a/converter/ppm/qrttoppm.c 2019-12-06 09:04:58.765176244 +0100 -+++ b/converter/ppm/qrttoppm.c 2019-12-06 08:38:15.105037862 +0100 +diff --git a/converter/ppm/qrttoppm.c b/converter/ppm/qrttoppm.c +index 935463e..653084c 100644 +--- a/converter/ppm/qrttoppm.c ++++ b/converter/ppm/qrttoppm.c @@ -46,7 +46,7 @@ main( argc, argv ) ppm_writeppminit( stdout, cols, rows, maxval, 0 ); @@ -1699,9 +1741,10 @@ diff -urNp a/converter/ppm/qrttoppm.c b/converter/ppm/qrttoppm.c if ( buf == (unsigned char *) 0 ) pm_error( "out of memory" ); -diff -urNp a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c ---- a/converter/ppm/sldtoppm.c 2019-12-06 09:04:58.764176235 +0100 -+++ b/converter/ppm/sldtoppm.c 2019-12-06 08:38:15.106037871 +0100 +diff --git a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c +index 2dc049f..2a482be 100644 +--- a/converter/ppm/sldtoppm.c ++++ b/converter/ppm/sldtoppm.c @@ -154,127 +154,85 @@ vscale(int * const px, @@ -1909,9 +1952,10 @@ diff -urNp a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c pixels = ppm_allocarray(pixcols = ixdots + 1, pixrows = iydots + 1); PPM_ASSIGN(rgbcolor, 0, 0, 0); ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0, -diff -urNp a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c ---- a/converter/ppm/ximtoppm.c 2019-12-06 09:04:58.766176253 +0100 -+++ b/converter/ppm/ximtoppm.c 2019-12-06 08:38:15.106037871 +0100 +diff --git a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c +index 75faac6..5758739 100644 +--- a/converter/ppm/ximtoppm.c ++++ b/converter/ppm/ximtoppm.c @@ -118,6 +118,7 @@ ReadXimHeader(FILE * const in_fp, header->bits_channel = atoi(a_head.bits_per_channel); header->alpha_flag = atoi(a_head.alpha_channel); @@ -1944,10 +1988,11 @@ diff -urNp a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c header->colors = (Color *)calloc((unsigned int)header->ncolors, sizeof(Color)); if (header->colors == NULL) { -diff -urNp a/editor/pamcut.c b/editor/pamcut.c ---- a/editor/pamcut.c 2019-12-06 09:04:58.737175993 +0100 -+++ b/editor/pamcut.c 2019-12-06 08:38:15.107037880 +0100 -@@ -773,6 +773,8 @@ cutOneImage(FILE * const ifP +diff --git a/editor/pamcut.c b/editor/pamcut.c +index db5b5b3..5fc0267 100644 +--- a/editor/pamcut.c ++++ b/editor/pamcut.c +@@ -773,6 +773,8 @@ cutOneImage(FILE * const ifP, outpam = inpam; /* Initial value -- most fields should be same */ outpam.file = ofP; @@ -1956,10 +2001,11 @@ diff -urNp a/editor/pamcut.c b/editor/pamcut.c outpam.width = rightcol - leftcol + 1; outpam.height = bottomrow - toprow + 1; -diff -urNp a/editor/pnmgamma.c b/editor/pnmgamma.c ---- a/editor/pnmgamma.c 2019-12-06 09:04:58.736175984 +0100 -+++ b/editor/pnmgamma.c 2019-12-06 08:38:15.107037880 +0100 -@@ -596,6 +596,7 @@ createGammaTables(enum transferFunction +diff --git a/editor/pnmgamma.c b/editor/pnmgamma.c +index b357b0d..ec612d3 100644 +--- a/editor/pnmgamma.c ++++ b/editor/pnmgamma.c +@@ -596,6 +596,7 @@ createGammaTables(enum transferFunction const transferFunction, xelval ** const btableP) { /* Allocate space for the tables. */ @@ -1967,10 +2013,11 @@ diff -urNp a/editor/pnmgamma.c b/editor/pnmgamma.c MALLOCARRAY(*rtableP, maxval+1); MALLOCARRAY(*gtableP, maxval+1); MALLOCARRAY(*btableP, maxval+1); -diff -urNp a/editor/pnmhisteq.c b/editor/pnmhisteq.c ---- a/editor/pnmhisteq.c 2019-12-06 09:04:58.735175975 +0100 -+++ b/editor/pnmhisteq.c 2019-12-06 08:38:15.108037889 +0100 -@@ -107,6 +107,7 @@ computeLuminosityHistogram(xel * const * +diff --git a/editor/pnmhisteq.c b/editor/pnmhisteq.c +index a339f73..c2c85a3 100644 +--- a/editor/pnmhisteq.c ++++ b/editor/pnmhisteq.c +@@ -107,6 +107,7 @@ computeLuminosityHistogram(xel * const * const xels, unsigned int pixelCount; unsigned int * lumahist; @@ -1978,9 +2025,10 @@ diff -urNp a/editor/pnmhisteq.c b/editor/pnmhisteq.c MALLOCARRAY(lumahist, maxval + 1); if (lumahist == NULL) pm_error("Out of storage allocating array for %u histogram elements", -diff -urNp a/editor/pnmindex.csh b/editor/pnmindex.csh ---- a/editor/pnmindex.csh 2019-12-06 09:04:58.735175975 +0100 -+++ b/editor/pnmindex.csh 2019-12-06 08:38:15.108037889 +0100 +diff --git a/editor/pnmindex.csh b/editor/pnmindex.csh +index c6f1e84..c513a84 100755 +--- a/editor/pnmindex.csh ++++ b/editor/pnmindex.csh @@ -1,5 +1,7 @@ #!/bin/csh -f # @@ -1989,10 +2037,11 @@ diff -urNp a/editor/pnmindex.csh b/editor/pnmindex.csh # pnmindex - build a visual index of a bunch of anymaps # # Copyright (C) 1991 by Jef Poskanzer. -diff -urNp a/editor/pnmpad.c b/editor/pnmpad.c ---- a/editor/pnmpad.c 2019-12-06 09:04:58.737175993 +0100 -+++ b/editor/pnmpad.c 2019-12-06 08:38:15.109037898 +0100 -@@ -634,6 +634,8 @@ main(int argc, const char ** argv) { +diff --git a/editor/pnmpad.c b/editor/pnmpad.c +index 55cdcd6..10da3af 100644 +--- a/editor/pnmpad.c ++++ b/editor/pnmpad.c +@@ -654,6 +654,8 @@ main(int argc, const char ** argv) { computePadSizes(cmdline, cols, rows, &lpad, &rpad, &tpad, &bpad); @@ -2000,10 +2049,11 @@ diff -urNp a/editor/pnmpad.c b/editor/pnmpad.c + overflow_add(cols + lpad, rpad); newcols = cols + lpad + rpad; - if (PNM_FORMAT_TYPE(format) == PBM_TYPE) -diff -urNp a/editor/pnmremap.c b/editor/pnmremap.c ---- a/editor/pnmremap.c 2019-12-06 09:04:58.737175993 +0100 -+++ b/editor/pnmremap.c 2019-12-06 08:38:15.109037898 +0100 + if (cmdline.reportonly) +diff --git a/editor/pnmremap.c b/editor/pnmremap.c +index 0c0096b..8b86cb7 100644 +--- a/editor/pnmremap.c ++++ b/editor/pnmremap.c @@ -468,6 +468,7 @@ fserr_init(struct pam * const pamP, unsigned int const fserrSize = pamP->width + 2; @@ -2020,9 +2070,11 @@ diff -urNp a/editor/pnmremap.c b/editor/pnmremap.c for (col = 0; col < pamP->width + 2; ++col) { unsigned int plane; for (plane = 0; plane < pamP->depth; ++plane) -diff -urNp a/editor/pnmremap.c.rej b/editor/pnmremap.c.rej ---- a/editor/pnmremap.c.rej 1970-01-01 01:00:00.000000000 +0100 -+++ b/editor/pnmremap.c.rej 2019-12-06 08:38:15.109037898 +0100 +diff --git a/editor/pnmremap.c.rej b/editor/pnmremap.c.rej +new file mode 100644 +index 0000000..c627c20 +--- /dev/null ++++ b/editor/pnmremap.c.rej @@ -0,0 +1,10 @@ +--- editor/pnmremap.c ++++ editor/pnmremap.c @@ -2034,10 +2086,11 @@ diff -urNp a/editor/pnmremap.c.rej b/editor/pnmremap.c.rej + for (col = 0; col < pamP->width + 2; ++col) { + unsigned int plane; + for (plane = 0; plane < pamP->depth; ++plane) -diff -urNp a/editor/pnmscalefixed.c b/editor/pnmscalefixed.c ---- a/editor/pnmscalefixed.c 2019-12-06 09:04:58.734175966 +0100 -+++ b/editor/pnmscalefixed.c 2019-12-06 08:38:15.109037898 +0100 -@@ -214,6 +214,7 @@ compute_output_dimensions(const struct c +diff --git a/editor/pnmscalefixed.c b/editor/pnmscalefixed.c +index 884ca31..747cd8f 100644 +--- a/editor/pnmscalefixed.c ++++ b/editor/pnmscalefixed.c +@@ -214,6 +214,7 @@ compute_output_dimensions(const struct cmdline_info cmdline, const int rows, const int cols, int * newrowsP, int * newcolsP) { @@ -2045,7 +2098,7 @@ diff -urNp a/editor/pnmscalefixed.c b/editor/pnmscalefixed.c if (cmdline.pixels) { if (rows * cols <= cmdline.pixels) { *newrowsP = rows; -@@ -265,6 +266,8 @@ compute_output_dimensions(const struct c +@@ -265,6 +266,8 @@ compute_output_dimensions(const struct cmdline_info cmdline, if (*newcolsP < 1) *newcolsP = 1; if (*newrowsP < 1) *newrowsP = 1; @@ -2064,10 +2117,11 @@ diff -urNp a/editor/pnmscalefixed.c b/editor/pnmscalefixed.c sxscale = SCALE * newcols / cols; syscale = SCALE * newrows / rows; -diff -urNp a/editor/ppmdither.c b/editor/ppmdither.c ---- a/editor/ppmdither.c 2019-12-06 09:04:58.736175984 +0100 -+++ b/editor/ppmdither.c 2019-12-06 08:38:15.110037907 +0100 -@@ -356,6 +356,11 @@ dithMatrix(unsigned int const dithPower) +diff --git a/editor/ppmdither.c b/editor/ppmdither.c +index ec1b977..e701e09 100644 +--- a/editor/ppmdither.c ++++ b/editor/ppmdither.c +@@ -356,6 +356,11 @@ dithMatrix(unsigned int const dithPower) { (dithDim * sizeof(*dithMat)) + /* pointers */ (dithDim * dithDim * sizeof(**dithMat)); /* data */ @@ -2079,9 +2133,10 @@ diff -urNp a/editor/ppmdither.c b/editor/ppmdither.c dithMat = malloc(dithMatSize); if (dithMat == NULL) -diff -urNp a/editor/specialty/pamoil.c b/editor/specialty/pamoil.c ---- a/editor/specialty/pamoil.c 2019-12-06 09:04:58.739176011 +0100 -+++ b/editor/specialty/pamoil.c 2019-12-06 08:38:15.110037907 +0100 +diff --git a/editor/specialty/pamoil.c b/editor/specialty/pamoil.c +index 6cb8d3a..6f4bde9 100644 +--- a/editor/specialty/pamoil.c ++++ b/editor/specialty/pamoil.c @@ -112,6 +112,7 @@ main(int argc, char *argv[] ) { tuples = pnm_readpam(ifp, &inpam, PAM_STRUCT_SIZE(tuple_type)); pm_close(ifp); @@ -2090,10 +2145,11 @@ diff -urNp a/editor/specialty/pamoil.c b/editor/specialty/pamoil.c MALLOCARRAY(hist, inpam.maxval + 1); if (hist == NULL) pm_error("Unable to allocate memory for histogram."); -diff -urNp a/lib/libpam.c b/lib/libpam.c ---- a/lib/libpam.c 2019-12-06 09:04:58.781176388 +0100 -+++ b/lib/libpam.c 2019-12-06 08:38:15.111037917 +0100 -@@ -225,7 +225,8 @@ allocPamRow(const struct pam * const pam +diff --git a/lib/libpam.c b/lib/libpam.c +index a8f140b..e6986f1 100644 +--- a/lib/libpam.c ++++ b/lib/libpam.c +@@ -225,7 +225,8 @@ allocPamRow(const struct pam * const pamP) { unsigned int const bytesPerTuple = allocationDepth(pamP) * sizeof(sample); tuple * tuplerow; @@ -2103,10 +2159,11 @@ diff -urNp a/lib/libpam.c b/lib/libpam.c if (tuplerow != NULL) { /* Now we initialize the pointers to the individual tuples -diff -urNp a/lib/libpammap.c b/lib/libpammap.c ---- a/lib/libpammap.c 2019-12-06 09:04:58.781176388 +0100 -+++ b/lib/libpammap.c 2019-12-06 08:38:15.111037917 +0100 -@@ -108,7 +108,9 @@ allocTupleIntListItem(struct pam * const +diff --git a/lib/libpammap.c b/lib/libpammap.c +index 2222491..ba27a4c 100644 +--- a/lib/libpammap.c ++++ b/lib/libpammap.c +@@ -108,7 +108,9 @@ allocTupleIntListItem(struct pam * const pamP) { */ struct tupleint_list_item * retval; @@ -2117,10 +2174,11 @@ diff -urNp a/lib/libpammap.c b/lib/libpammap.c sizeof(*retval) - sizeof(retval->tupleint.tuple) + pamP->depth * sizeof(sample); -diff -urNp a/lib/libpm.c b/lib/libpm.c ---- a/lib/libpm.c 2019-12-06 09:04:58.781176388 +0100 -+++ b/lib/libpm.c 2019-12-06 08:38:15.111037917 +0100 -@@ -888,5 +888,53 @@ pm_parse_height(const char * const arg) +diff --git a/lib/libpm.c b/lib/libpm.c +index 47a2f49..a263598 100644 +--- a/lib/libpm.c ++++ b/lib/libpm.c +@@ -888,5 +888,53 @@ pm_parse_height(const char * const arg) { return height; } @@ -2174,10 +2232,11 @@ diff -urNp a/lib/libpm.c b/lib/libpm.c + return realloc(a, b*c); +} -diff -urNp a/lib/pm.h b/lib/pm.h ---- a/lib/pm.h 2019-12-06 09:04:58.780176379 +0100 -+++ b/lib/pm.h 2019-12-06 08:38:15.112037926 +0100 -@@ -442,5 +442,12 @@ pm_parse_height(const char * const arg); +diff --git a/lib/pm.h b/lib/pm.h +index 3fc92fb..1e30ce9 100644 +--- a/lib/pm.h ++++ b/lib/pm.h +@@ -441,5 +441,12 @@ pm_parse_height(const char * const arg); } #endif @@ -2190,9 +2249,11 @@ diff -urNp a/lib/pm.h b/lib/pm.h + #endif -diff -urNp a/lib/pm.h.orig b/lib/pm.h.orig ---- a/lib/pm.h.orig 1970-01-01 01:00:00.000000000 +0100 -+++ b/lib/pm.h.orig 2019-12-06 08:37:56.816870379 +0100 +diff --git a/lib/pm.h.orig b/lib/pm.h.orig +new file mode 100644 +index 0000000..471f445 +--- /dev/null ++++ b/lib/pm.h.orig @@ -0,0 +1,446 @@ +/* pm.h - interface to format-independent part of libpbm. +** @@ -2640,10 +2701,11 @@ diff -urNp a/lib/pm.h.orig b/lib/pm.h.orig + + +#endif -diff -urNp a/other/pnmcolormap.c b/other/pnmcolormap.c ---- a/other/pnmcolormap.c 2019-12-06 09:04:58.789176460 +0100 -+++ b/other/pnmcolormap.c 2019-12-06 08:38:15.112037926 +0100 -@@ -1002,6 +1002,7 @@ colormapToSquare(struct pam * const pamP +diff --git a/other/pnmcolormap.c b/other/pnmcolormap.c +index 7da3122..dafa390 100644 +--- a/other/pnmcolormap.c ++++ b/other/pnmcolormap.c +@@ -1002,6 +1002,7 @@ colormapToSquare(struct pam * const pamP, pamP->width = intsqrt; else pamP->width = intsqrt + 1; @@ -2651,9 +2713,11 @@ diff -urNp a/other/pnmcolormap.c b/other/pnmcolormap.c } { unsigned int const intQuotient = colormap.size / pamP->width; -diff -urNp a/other/pnmcolormap.c.orig b/other/pnmcolormap.c.orig ---- a/other/pnmcolormap.c.orig 1970-01-01 01:00:00.000000000 +0100 -+++ b/other/pnmcolormap.c.orig 2019-12-06 08:37:56.824870452 +0100 +diff --git a/other/pnmcolormap.c.orig b/other/pnmcolormap.c.orig +new file mode 100644 +index 0000000..7da3122 +--- /dev/null ++++ b/other/pnmcolormap.c.orig @@ -0,0 +1,1143 @@ +/****************************************************************************** + pnmcolormap.c @@ -3798,9 +3862,537 @@ diff -urNp a/other/pnmcolormap.c.orig b/other/pnmcolormap.c.orig + + + -diff -urNp a/urt/rle_addhist.c b/urt/rle_addhist.c ---- a/urt/rle_addhist.c 2019-12-06 09:04:58.741176029 +0100 -+++ b/urt/rle_addhist.c 2019-12-06 08:38:15.113037935 +0100 +diff --git a/urt/Runput.c b/urt/Runput.c +index 3bc562a..645a376 100644 +--- a/urt/Runput.c ++++ b/urt/Runput.c +@@ -202,10 +202,11 @@ RunSetup(rle_hdr * the_hdr) + if ( the_hdr->background != 0 ) + { + register int i; +- register rle_pixel *background = +- (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); +- register int *bg_color; +- /* ++ register rle_pixel *background; ++ register int *bg_color; ++ ++ overflow_add(the_hdr->ncolors,1); ++ background = (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); /* + * If even number of bg color bytes, put out one more to get to + * 16 bit boundary. + */ +@@ -224,7 +225,7 @@ RunSetup(rle_hdr * the_hdr) + /* Big-endian machines are harder */ + register int i, nmap = (1 << the_hdr->cmaplen) * + the_hdr->ncmap; +- register char *h_cmap = (char *)malloc( nmap * 2 ); ++ register char *h_cmap = (char *)malloc2( nmap, 2 ); + if ( h_cmap == NULL ) + { + fprintf( stderr, +diff --git a/urt/rle.h b/urt/rle.h +index 0071774..6a905ba 100644 +--- a/urt/rle.h ++++ b/urt/rle.h +@@ -152,6 +152,17 @@ rle_hdr /* End of typedef. */ + */ + extern rle_hdr rle_dflt_hdr; + ++/* ++ * Provided by pm library ++ */ ++ ++extern void overflow_add(int, int); ++#define overflow2(a,b) __overflow2(a,b) ++extern void __overflow2(int, int); ++extern void overflow3(int, int, int); ++extern void *malloc2(int, int); ++extern void *malloc3(int, int, int); ++extern void *realloc2(void *, int, int); + + /* Declare RLE library routines. */ + +diff --git a/urt/rle.h.orig b/urt/rle.h.orig +new file mode 100644 +index 0000000..59d2670 +--- /dev/null ++++ b/urt/rle.h.orig +@@ -0,0 +1,470 @@ ++/* ++ * This software is copyrighted as noted below. It may be freely copied, ++ * modified, and redistributed, provided that the copyright notice is ++ * preserved on all copies. ++ * ++ * There is no warranty or other guarantee of fitness for this software, ++ * it is provided solely "as is". Bug reports or fixes may be sent ++ * to the author, who may or may not act on them as he desires. ++ * ++ * You may not include this software in a program or other software product ++ * without supplying the source, or without informing the end-user that the ++ * source is available for no extra charge. ++ * ++ * If you modify this software, you should include a notice giving the ++ * name of the person performing the modification, the date of modification, ++ * and the reason for such modification. ++ */ ++/* ++ * rle.h - Global declarations for Utah Raster Toolkit RLE programs. ++ * ++ * Author: Todd W. Fuqua ++ * Computer Science Dept. ++ * University of Utah ++ * Date: Sun Jul 29 1984 ++ * Copyright (c) 1984 Todd W. Fuqua ++ * ++ * $Id: rle.h,v 3.0.1.5 1992/04/30 14:05:56 spencer Exp $ ++ */ ++ ++#ifndef RLE_H ++#define RLE_H ++ ++#include /* Declare FILE. */ ++#include ++ ++enum rle_dispatch { ++ NO_DISPATCH = -1, ++ RUN_DISPATCH = 0 ++}; ++ ++/* **************************************************************** ++ * TAG( rle_pixel rle_map ) ++ * ++ * Typedef for 8-bit (or less) pixel data. ++ * ++ * Typedef for 16-bit color map data. ++ */ ++typedef unsigned char rle_pixel; ++typedef unsigned short rle_map; ++ ++/* ++ * Defines for traditional channel numbers. ++ */ ++#define RLE_RED 0 /* Red channel traditionally here. */ ++#define RLE_GREEN 1 /* Green channel traditionally here. */ ++#define RLE_BLUE 2 /* Blue channel traditionally here. */ ++#define RLE_ALPHA -1 /* Alpha channel here. */ ++ ++/* ++ * Return values from rle_get_setup. ++ */ ++#define RLE_SUCCESS 0 ++#define RLE_NOT_RLE -1 ++#define RLE_NO_SPACE -2 ++#define RLE_EMPTY -3 ++#define RLE_EOF -4 ++ ++/* ++ * "Magic" value for is_init field. Pi * 2^29. ++ */ ++#define RLE_INIT_MAGIC 0x6487ED51L ++ ++/* ++ * TAG( rle_hdr ) ++ * ++ * Definition of header structure used by RLE routines. ++ */ ++ ++#ifndef c_plusplus ++typedef ++#endif ++ struct rle_hdr { ++ enum rle_dispatch dispatch; /* Type of file to create. */ ++ int ncolors; /* Number of color channels. */ ++ int * bg_color; /* Pointer to bg color vector. */ ++ int alpha; /* If !0, save alpha channel. */ ++ int background; /* 0->just save all pixels, */ ++ /* 1->overlay, 2->clear to bg first. */ ++ int xmin; /* Lower X bound (left.) */ ++ int xmax; /* Upper X bound (right.) */ ++ int ymin; /* Lower Y bound (bottom.) */ ++ int ymax; /* Upper Y bound (top.) */ ++ int ncmap; /* Number of color channels in color map. */ ++ /* Map only saved if != 0. */ ++ int cmaplen; /* Log2 of color map length. */ ++ rle_map * cmap; /* Pointer to color map array. */ ++ const char ** comments; /* Pointer to array of pointers to comments. */ ++ FILE * rle_file; /* Input or output file. */ ++ /* ++ * Bit map of channels to read/save. Indexed by (channel mod 256). ++ * Alpha channel sets bit 255. ++ * ++ * Indexing (0 <= c <= 255): ++ * bits[c/8] & (1 << (c%8)) ++ */ ++#define RLE_SET_BIT(glob,bit) \ ++ ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7))) ++#define RLE_CLR_BIT(glob,bit) \ ++ ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7))) ++#define RLE_BIT(glob,bit) \ ++ ((glob).bits[((bit)&0xff)/8] & (1<<((bit)&0x7))) ++ char bits[256/8]; ++ /* Set to magic pattern if following fields are initialized. */ ++ /* This gives a 2^(-32) chance of missing. */ ++ long int is_init; ++ /* Command, file name and image number for error messages. */ ++ const char *cmd; ++ const char *file_name; ++ int img_num; ++ /* ++ * Local storage for rle_getrow & rle_putrow. ++ * rle_getrow has ++ * scan_y int current Y scanline. ++ * vert_skip int number of lines to skip. ++ * rle_putrow has ++ * nblank int number of blank lines. ++ * brun short(*)[2] Array of background runs. ++ * fileptr long Position in output file. ++ */ ++ union { ++ struct { ++ int scan_y, ++ vert_skip; ++ char is_eof, /* Set when EOF or EofOp encountered. */ ++ is_seek; /* If true, can seek input file. */ ++ } get; ++ struct { ++ int nblank; ++ short (*brun)[2]; ++ long fileptr; ++ } put; ++ } priv; ++ } ++#ifndef c_plusplus ++rle_hdr /* End of typedef. */ ++#endif ++; ++ ++/* ++ * TAG( rle_dflt_hdr ) ++ * ++ * Global variable with possibly useful default values. ++ */ ++extern rle_hdr rle_dflt_hdr; ++ ++ ++/* Declare RLE library routines. */ ++ ++/***************************************************************** ++ * TAG( rle_get_error ) ++ * ++ * Print an error message based on the error code returned by ++ * rle_get_setup. ++ */ ++extern int rle_get_error( int code, ++ const char *pgmname, ++ const char *fname ); ++ ++/* From rle_getrow.c */ ++ ++/***************************************************************** ++ * TAG( rle_debug ) ++ * ++ * Turn RLE debugging on or off. ++ */ ++extern void rle_debug( int on_off ); ++ ++int ++rle_get_setup(rle_hdr * const the_hdr); ++ ++/***************************************************************** ++ * TAG( rle_get_setup_ok ) ++ * ++ * Call rle_get_setup. If it returns an error code, call ++ * rle_get_error to print the error message, then exit with the error ++ * code. ++ */ ++extern void rle_get_setup_ok( rle_hdr *the_hdr, ++ const char *prog_name, ++ const char *file_name); ++ ++/***************************************************************** ++ * TAG( rle_getrow ) ++ * ++ * Read a scanline worth of data from an RLE file. ++ */ ++extern int rle_getrow( rle_hdr * the_hdr, ++ rle_pixel * scanline[] ); ++ ++/* From rle_getskip.c */ ++ ++/***************************************************************** ++ * TAG( rle_getskip ) ++ * Skip a scanline, return the number of the next one. ++ */ ++extern unsigned int rle_getskip( rle_hdr *the_hdr ); ++ ++/* From rle_hdr.c. */ ++ ++/***************************************************************** ++ * TAG( rle_names ) ++ * ++ * Load the command and file names into the rle_hdr. ++ */ ++extern void rle_names( rle_hdr *the_hdr, ++ const char *pgmname, ++ const char *fname, ++ int img_num ); ++ ++/***************************************************************** ++ * TAG( rle_hdr_cp ) ++ * ++ * Make a "safe" copy of a rle_hdr structure. ++ */ ++extern rle_hdr * rle_hdr_cp( rle_hdr *from_hdr, ++ rle_hdr *to_hdr ); ++ ++/***************************************************************** ++ * TAG( rle_hdr_init ) ++ * ++ * Initialize a rle_hdr structure. ++ */ ++extern rle_hdr * rle_hdr_init( rle_hdr *the_hdr ); ++ ++/***************************************************************** ++ * TAG( rle_hdr_clear ) ++ * ++ */ ++extern void rle_hdr_clear( rle_hdr *the_hdr ); ++ ++/* From rle_putrow.c. */ ++ ++/***************************************************************** ++ * TAG( rgb_to_bw ) ++ * ++ * Converts RGB data to gray data via the NTSC Y transform. ++ */ ++extern void rgb_to_bw( rle_pixel *red_row, ++ rle_pixel *green_row, ++ rle_pixel *blue_row, ++ rle_pixel *bw_row, ++ int rowlen ); ++ ++/***************************************************************** ++ * TAG( rle_puteof ) ++ * ++ * Write an End-of-image opcode to the RLE file. ++ */ ++extern void rle_puteof( rle_hdr *the_hdr ); ++ ++/***************************************************************** ++ * TAG( rle_putrow ) ++ * ++ * Write a scanline of data to the RLE file. ++ */ ++extern void rle_putrow( rle_pixel *rows[], int rowlen, rle_hdr *the_hdr ); ++ ++/***************************************************************** ++ * TAG( rle_put_init ) ++ * ++ * Initialize header for output, but don't write it to the file. ++ */ ++extern void rle_put_init( rle_hdr * the_hdr ); ++ ++/***************************************************************** ++ * TAG( rle_put_setup ) ++ * ++ * Write header information to a new RLE image file. ++ */ ++extern void rle_put_setup( rle_hdr * the_hdr ); ++ ++/***************************************************************** ++ * TAG( rle_skiprow ) ++ * ++ * Skip nrow scanlines in the output file. ++ */ ++extern void rle_skiprow( rle_hdr *the_hdr, int nrow ); ++ ++/* From rle_cp.c */ ++/***************************************************************** ++ * TAG( rle_cp ) ++ * Copy image data from input to output with minimal interpretation. ++ */ ++extern void rle_cp( rle_hdr *in_hdr, rle_hdr *out_hdr ); ++ ++/* From rle_row_alc.c. */ ++/***************************************************************** ++ * TAG( rle_row_alloc ) ++ * ++ * Allocate scanline memory for use by rle_getrow. ++ */ ++extern int rle_row_alloc( rle_hdr * the_hdr, ++ rle_pixel *** scanp ); ++ ++/***************************************************************** ++ * TAG( rle_row_free ) ++ * ++ * Free the above. ++ */ ++extern void rle_row_free( rle_hdr *the_hdr, rle_pixel **scanp ); ++ ++/* From buildmap.c. */ ++/* ++ * buildmap - build a more usable colormap from data in the_hdr struct. ++ */ ++extern rle_pixel **buildmap( rle_hdr *the_hdr, ++ int minmap, ++ double orig_gamma, ++ double new_gamma ); ++ ++/* From rle_getcom.c. */ ++/***************************************************************** ++ * TAG( rle_getcom ) ++ * ++ * Get a specific comment from the image comments. ++ */ ++const char * ++rle_getcom(const char * const name, ++ rle_hdr * const the_hdr); ++ ++/* From rle_putcom.c. */ ++ ++/* Delete a specific comment from the image comments. */ ++const char * ++rle_delcom(const char * const name, ++ rle_hdr * const the_hdr); ++ ++/* Put (or replace) a comment into the image comments. */ ++const char * ++rle_putcom(const char * const value, ++ rle_hdr * const the_hdr); ++ ++/* From dither.c. */ ++/***************************************************************** ++ * TAG( bwdithermap ) ++ * Create a color map for ordered dithering in grays. ++ */ ++extern void bwdithermap( int levels, double gamma, int bwmap[], ++ int divN[256], int modN[256], int magic[16][16] ); ++/***************************************************************** ++ * TAG( ditherbw ) ++ * Dither a gray-scale value. ++ */ ++extern int ditherbw( int x, int y, int val, ++ int divN[256], int modN[256], int magic[16][16] ); ++/***************************************************************** ++ * TAG( dithergb ) ++ * Dither a color value. ++ */ ++extern int dithergb( int x, int y, int r, int g, int b, ++ int divN[256], int modN[256], int magic[16][16] ); ++/***************************************************************** ++ * TAG( dithermap ) ++ * Create a color map for ordered dithering in color. ++ */ ++extern void dithermap( int levels, double gamma, int rgbmap[][3], ++ int divN[256], int modN[256], int magic[16][16] ); ++/***************************************************************** ++ * TAG( make_square ) ++ * Make a 16x16 magic square for ordered dithering. ++ */ ++extern void make_square( double N, int divN[256], int modN[256], ++ int magic[16][16] ); ++ ++/* From float_to_exp.c. */ ++/***************************************************************** ++ * TAG( float_to_exp ) ++ * Convert a list of floating point numbers to "exp" format. ++ */ ++extern void float_to_exp( int count, float * floats, rle_pixel * pixels ); ++ ++/* From rle_open_f.c. */ ++/***************************************************************** ++ * TAG( rle_open_f ) ++ * ++ * Open an input/output file with default. ++ */ ++FILE * ++rle_open_f(const char * prog_name, const char * file_name, ++ const char * mode); ++ ++/***************************************************************** ++ * TAG( rle_open_f_noexit ) ++ * ++ * Open an input/output file with default. ++ */ ++FILE * ++rle_open_f_noexit(const char * const prog_name, ++ const char * const file_name, ++ const char * const mode); ++ ++/***************************************************************** ++ * TAG( rle_close_f ) ++ * ++ * Close a file opened by rle_open_f. If the file is stdin or stdout, ++ * it will not be closed. ++ */ ++extern void ++rle_close_f( FILE *fd ); ++ ++/* From colorquant.c. */ ++/***************************************************************** ++ * TAG( colorquant ) ++ * Compute a colormap for quantizing an image to a limited set of colors. ++ */ ++extern int colorquant( rle_pixel *red, rle_pixel *green, rle_pixel *blue, ++ unsigned long pixels, rle_pixel *colormap[3], ++ int colors, int bits, ++ rle_pixel *rgbmap, int fast, int otherimages ); ++ ++/* From rle_addhist.c. */ ++ ++/* Append history information to the HISTORY comment. */ ++void ++rle_addhist(char * argv[], ++ rle_hdr * const in_hdr, ++ rle_hdr * const out_hdr); ++ ++/* From cmd_name.c. */ ++/***************************************************************** ++ * TAG( cmd_name ) ++ * Extract command name from argv. ++ */ ++extern char *cmd_name( char **argv ); ++ ++/* From scanargs.c. */ ++/***************************************************************** ++ * TAG( scanargs ) ++ * Scan command argument list and parse arguments. ++ */ ++extern int scanargs( int argc, ++ char **argv, ++ const char *format, ++ ... ); ++ ++/* From hilbert.c */ ++/***************************************************************** ++ * TAG( hilbert_i2c ) ++ * Convert an index into a Hilbert curve to a set of coordinates. ++ */ ++extern void hilbert_c2i( int n, int m, int a[], long int *r ); ++ ++/***************************************************************** ++ * TAG( hilbert_c2i ) ++ * Convert coordinates of a point on a Hilbert curve to its index. ++ */ ++extern void hilbert_i2c( int n, int m, long int r, int a[] ); ++ ++/* From inv_cmap.c */ ++/***************************************************************** ++ * TAG( inv_cmap ) ++ * Compute an inverse colormap efficiently. ++ */ ++extern void inv_cmap( int colors, ++ unsigned char *colormap[3], ++ int bits, ++ unsigned long *dist_buf, ++ unsigned char *rgbmap ); ++ ++#endif /* RLE_H */ +diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c +index b165175..e09ed94 100644 +--- a/urt/rle_addhist.c ++++ b/urt/rle_addhist.c @@ -70,13 +70,18 @@ rle_addhist(char * argv[], return; @@ -3834,9 +4426,10 @@ diff -urNp a/urt/rle_addhist.c b/urt/rle_addhist.c ++length; /*Cater for the null. */ -diff -urNp a/urt/rle_getrow.c b/urt/rle_getrow.c ---- a/urt/rle_getrow.c 2019-12-06 09:04:58.740176020 +0100 -+++ b/urt/rle_getrow.c 2019-12-06 08:38:15.113037935 +0100 +diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c +index ae220f5..39010ba 100644 +--- a/urt/rle_getrow.c ++++ b/urt/rle_getrow.c @@ -164,6 +164,7 @@ rle_get_setup(rle_hdr * const the_hdr) { char * cp; @@ -3845,9 +4438,11 @@ diff -urNp a/urt/rle_getrow.c b/urt/rle_getrow.c evenlen = (comlen + 1) & ~1; /* make it even */ if (evenlen) { MALLOCARRAY(comment_buf, evenlen); -diff -urNp a/urt/rle_getrow.c.orig b/urt/rle_getrow.c.orig ---- a/urt/rle_getrow.c.orig 1970-01-01 01:00:00.000000000 +0100 -+++ b/urt/rle_getrow.c.orig 2019-12-06 08:37:56.784870085 +0100 +diff --git a/urt/rle_getrow.c.orig b/urt/rle_getrow.c.orig +new file mode 100644 +index 0000000..ae220f5 +--- /dev/null ++++ b/urt/rle_getrow.c.orig @@ -0,0 +1,520 @@ +/* + * This software is copyrighted as noted below. It may be freely copied, @@ -4369,30 +4964,10 @@ diff -urNp a/urt/rle_getrow.c.orig b/urt/rle_getrow.c.orig + + + -diff -urNp a/urt/rle.h b/urt/rle.h ---- a/urt/rle.h 2019-12-06 09:04:58.741176029 +0100 -+++ b/urt/rle.h 2019-12-06 08:38:15.113037935 +0100 -@@ -153,6 +153,17 @@ rle_hdr /* End of typedef. * - */ - extern rle_hdr rle_dflt_hdr; - -+/* -+ * Provided by pm library -+ */ -+ -+extern void overflow_add(int, int); -+#define overflow2(a,b) __overflow2(a,b) -+extern void __overflow2(int, int); -+extern void overflow3(int, int, int); -+extern void *malloc2(int, int); -+extern void *malloc3(int, int, int); -+extern void *realloc2(void *, int, int); - - /* Declare RLE library routines. */ - -diff -urNp a/urt/rle_hdr.c b/urt/rle_hdr.c ---- a/urt/rle_hdr.c 2019-12-06 09:04:58.741176029 +0100 -+++ b/urt/rle_hdr.c 2019-12-06 09:04:18.225811488 +0100 +diff --git a/urt/rle_hdr.c b/urt/rle_hdr.c +index 1edb7a3..d306607 100644 +--- a/urt/rle_hdr.c ++++ b/urt/rle_hdr.c @@ -148,7 +148,7 @@ rle_hdr_cp(rle_hdr * const fromHdrP, if (toHdrP->cmap) { size_t const size = @@ -4419,9 +4994,11 @@ diff -urNp a/urt/rle_hdr.c b/urt/rle_hdr.c size *= sizeof(char *); toHdrP->comments = malloc(size); if (!toHdrP->comments) -diff -urNp a/urt/rle_hdr.c.orig b/urt/rle_hdr.c.orig ---- a/urt/rle_hdr.c.orig 1970-01-01 01:00:00.000000000 +0100 -+++ b/urt/rle_hdr.c.orig 2019-12-06 08:38:15.114037944 +0100 +diff --git a/urt/rle_hdr.c.orig b/urt/rle_hdr.c.orig +new file mode 100644 +index 0000000..1edb7a3 +--- /dev/null ++++ b/urt/rle_hdr.c.orig @@ -0,0 +1,286 @@ +/* + * This software is copyrighted as noted below. It may be freely copied, @@ -4709,9 +5286,11 @@ diff -urNp a/urt/rle_hdr.c.orig b/urt/rle_hdr.c.orig + + + -diff -urNp a/urt/rle_hdr.c.rej b/urt/rle_hdr.c.rej ---- a/urt/rle_hdr.c.rej 1970-01-01 01:00:00.000000000 +0100 -+++ b/urt/rle_hdr.c.rej 2019-12-06 08:38:15.114037944 +0100 +diff --git a/urt/rle_hdr.c.rej b/urt/rle_hdr.c.rej +new file mode 100644 +index 0000000..62f2fb0 +--- /dev/null ++++ b/urt/rle_hdr.c.rej @@ -0,0 +1,63 @@ +--- urt/rle_hdr.c ++++ urt/rle_hdr.c @@ -4776,484 +5355,11 @@ diff -urNp a/urt/rle_hdr.c.rej b/urt/rle_hdr.c.rej + size *= sizeof(char *); + to_hdr->comments = (CONST_DECL char **)malloc( size ); + RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->comments, "comments" ); -diff -urNp a/urt/rle.h.orig b/urt/rle.h.orig ---- a/urt/rle.h.orig 1970-01-01 01:00:00.000000000 +0100 -+++ b/urt/rle.h.orig 2019-12-06 08:37:56.784870085 +0100 -@@ -0,0 +1,470 @@ -+/* -+ * This software is copyrighted as noted below. It may be freely copied, -+ * modified, and redistributed, provided that the copyright notice is -+ * preserved on all copies. -+ * -+ * There is no warranty or other guarantee of fitness for this software, -+ * it is provided solely "as is". Bug reports or fixes may be sent -+ * to the author, who may or may not act on them as he desires. -+ * -+ * You may not include this software in a program or other software product -+ * without supplying the source, or without informing the end-user that the -+ * source is available for no extra charge. -+ * -+ * If you modify this software, you should include a notice giving the -+ * name of the person performing the modification, the date of modification, -+ * and the reason for such modification. -+ */ -+/* -+ * rle.h - Global declarations for Utah Raster Toolkit RLE programs. -+ * -+ * Author: Todd W. Fuqua -+ * Computer Science Dept. -+ * University of Utah -+ * Date: Sun Jul 29 1984 -+ * Copyright (c) 1984 Todd W. Fuqua -+ * -+ * $Id: rle.h,v 3.0.1.5 1992/04/30 14:05:56 spencer Exp $ -+ */ -+ -+#ifndef RLE_H -+#define RLE_H -+ -+#include /* Declare FILE. */ -+#include -+ -+enum rle_dispatch { -+ NO_DISPATCH = -1, -+ RUN_DISPATCH = 0 -+}; -+ -+/* **************************************************************** -+ * TAG( rle_pixel rle_map ) -+ * -+ * Typedef for 8-bit (or less) pixel data. -+ * -+ * Typedef for 16-bit color map data. -+ */ -+typedef unsigned char rle_pixel; -+typedef unsigned short rle_map; -+ -+/* -+ * Defines for traditional channel numbers. -+ */ -+#define RLE_RED 0 /* Red channel traditionally here. */ -+#define RLE_GREEN 1 /* Green channel traditionally here. */ -+#define RLE_BLUE 2 /* Blue channel traditionally here. */ -+#define RLE_ALPHA -1 /* Alpha channel here. */ -+ -+/* -+ * Return values from rle_get_setup. -+ */ -+#define RLE_SUCCESS 0 -+#define RLE_NOT_RLE -1 -+#define RLE_NO_SPACE -2 -+#define RLE_EMPTY -3 -+#define RLE_EOF -4 -+ -+/* -+ * "Magic" value for is_init field. Pi * 2^29. -+ */ -+#define RLE_INIT_MAGIC 0x6487ED51L -+ -+/* -+ * TAG( rle_hdr ) -+ * -+ * Definition of header structure used by RLE routines. -+ */ -+ -+#ifndef c_plusplus -+typedef -+#endif -+ struct rle_hdr { -+ enum rle_dispatch dispatch; /* Type of file to create. */ -+ int ncolors; /* Number of color channels. */ -+ int * bg_color; /* Pointer to bg color vector. */ -+ int alpha; /* If !0, save alpha channel. */ -+ int background; /* 0->just save all pixels, */ -+ /* 1->overlay, 2->clear to bg first. */ -+ int xmin; /* Lower X bound (left.) */ -+ int xmax; /* Upper X bound (right.) */ -+ int ymin; /* Lower Y bound (bottom.) */ -+ int ymax; /* Upper Y bound (top.) */ -+ int ncmap; /* Number of color channels in color map. */ -+ /* Map only saved if != 0. */ -+ int cmaplen; /* Log2 of color map length. */ -+ rle_map * cmap; /* Pointer to color map array. */ -+ const char ** comments; /* Pointer to array of pointers to comments. */ -+ FILE * rle_file; /* Input or output file. */ -+ /* -+ * Bit map of channels to read/save. Indexed by (channel mod 256). -+ * Alpha channel sets bit 255. -+ * -+ * Indexing (0 <= c <= 255): -+ * bits[c/8] & (1 << (c%8)) -+ */ -+#define RLE_SET_BIT(glob,bit) \ -+ ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7))) -+#define RLE_CLR_BIT(glob,bit) \ -+ ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7))) -+#define RLE_BIT(glob,bit) \ -+ ((glob).bits[((bit)&0xff)/8] & (1<<((bit)&0x7))) -+ char bits[256/8]; -+ /* Set to magic pattern if following fields are initialized. */ -+ /* This gives a 2^(-32) chance of missing. */ -+ long int is_init; -+ /* Command, file name and image number for error messages. */ -+ const char *cmd; -+ const char *file_name; -+ int img_num; -+ /* -+ * Local storage for rle_getrow & rle_putrow. -+ * rle_getrow has -+ * scan_y int current Y scanline. -+ * vert_skip int number of lines to skip. -+ * rle_putrow has -+ * nblank int number of blank lines. -+ * brun short(*)[2] Array of background runs. -+ * fileptr long Position in output file. -+ */ -+ union { -+ struct { -+ int scan_y, -+ vert_skip; -+ char is_eof, /* Set when EOF or EofOp encountered. */ -+ is_seek; /* If true, can seek input file. */ -+ } get; -+ struct { -+ int nblank; -+ short (*brun)[2]; -+ long fileptr; -+ } put; -+ } priv; -+ } -+#ifndef c_plusplus -+rle_hdr /* End of typedef. */ -+#endif -+; -+ -+/* -+ * TAG( rle_dflt_hdr ) -+ * -+ * Global variable with possibly useful default values. -+ */ -+extern rle_hdr rle_dflt_hdr; -+ -+ -+/* Declare RLE library routines. */ -+ -+/***************************************************************** -+ * TAG( rle_get_error ) -+ * -+ * Print an error message based on the error code returned by -+ * rle_get_setup. -+ */ -+extern int rle_get_error( int code, -+ const char *pgmname, -+ const char *fname ); -+ -+/* From rle_getrow.c */ -+ -+/***************************************************************** -+ * TAG( rle_debug ) -+ * -+ * Turn RLE debugging on or off. -+ */ -+extern void rle_debug( int on_off ); -+ -+int -+rle_get_setup(rle_hdr * const the_hdr); -+ -+/***************************************************************** -+ * TAG( rle_get_setup_ok ) -+ * -+ * Call rle_get_setup. If it returns an error code, call -+ * rle_get_error to print the error message, then exit with the error -+ * code. -+ */ -+extern void rle_get_setup_ok( rle_hdr *the_hdr, -+ const char *prog_name, -+ const char *file_name); -+ -+/***************************************************************** -+ * TAG( rle_getrow ) -+ * -+ * Read a scanline worth of data from an RLE file. -+ */ -+extern int rle_getrow( rle_hdr * the_hdr, -+ rle_pixel * scanline[] ); -+ -+/* From rle_getskip.c */ -+ -+/***************************************************************** -+ * TAG( rle_getskip ) -+ * Skip a scanline, return the number of the next one. -+ */ -+extern unsigned int rle_getskip( rle_hdr *the_hdr ); -+ -+/* From rle_hdr.c. */ -+ -+/***************************************************************** -+ * TAG( rle_names ) -+ * -+ * Load the command and file names into the rle_hdr. -+ */ -+extern void rle_names( rle_hdr *the_hdr, -+ const char *pgmname, -+ const char *fname, -+ int img_num ); -+ -+/***************************************************************** -+ * TAG( rle_hdr_cp ) -+ * -+ * Make a "safe" copy of a rle_hdr structure. -+ */ -+extern rle_hdr * rle_hdr_cp( rle_hdr *from_hdr, -+ rle_hdr *to_hdr ); -+ -+/***************************************************************** -+ * TAG( rle_hdr_init ) -+ * -+ * Initialize a rle_hdr structure. -+ */ -+extern rle_hdr * rle_hdr_init( rle_hdr *the_hdr ); -+ -+/***************************************************************** -+ * TAG( rle_hdr_clear ) -+ * -+ */ -+extern void rle_hdr_clear( rle_hdr *the_hdr ); -+ -+/* From rle_putrow.c. */ -+ -+/***************************************************************** -+ * TAG( rgb_to_bw ) -+ * -+ * Converts RGB data to gray data via the NTSC Y transform. -+ */ -+extern void rgb_to_bw( rle_pixel *red_row, -+ rle_pixel *green_row, -+ rle_pixel *blue_row, -+ rle_pixel *bw_row, -+ int rowlen ); -+ -+/***************************************************************** -+ * TAG( rle_puteof ) -+ * -+ * Write an End-of-image opcode to the RLE file. -+ */ -+extern void rle_puteof( rle_hdr *the_hdr ); -+ -+/***************************************************************** -+ * TAG( rle_putrow ) -+ * -+ * Write a scanline of data to the RLE file. -+ */ -+extern void rle_putrow( rle_pixel *rows[], int rowlen, rle_hdr *the_hdr ); -+ -+/***************************************************************** -+ * TAG( rle_put_init ) -+ * -+ * Initialize header for output, but don't write it to the file. -+ */ -+extern void rle_put_init( rle_hdr * the_hdr ); -+ -+/***************************************************************** -+ * TAG( rle_put_setup ) -+ * -+ * Write header information to a new RLE image file. -+ */ -+extern void rle_put_setup( rle_hdr * the_hdr ); -+ -+/***************************************************************** -+ * TAG( rle_skiprow ) -+ * -+ * Skip nrow scanlines in the output file. -+ */ -+extern void rle_skiprow( rle_hdr *the_hdr, int nrow ); -+ -+/* From rle_cp.c */ -+/***************************************************************** -+ * TAG( rle_cp ) -+ * Copy image data from input to output with minimal interpretation. -+ */ -+extern void rle_cp( rle_hdr *in_hdr, rle_hdr *out_hdr ); -+ -+/* From rle_row_alc.c. */ -+/***************************************************************** -+ * TAG( rle_row_alloc ) -+ * -+ * Allocate scanline memory for use by rle_getrow. -+ */ -+extern int rle_row_alloc( rle_hdr * the_hdr, -+ rle_pixel *** scanp ); -+ -+/***************************************************************** -+ * TAG( rle_row_free ) -+ * -+ * Free the above. -+ */ -+extern void rle_row_free( rle_hdr *the_hdr, rle_pixel **scanp ); -+ -+/* From buildmap.c. */ -+/* -+ * buildmap - build a more usable colormap from data in the_hdr struct. -+ */ -+extern rle_pixel **buildmap( rle_hdr *the_hdr, -+ int minmap, -+ double orig_gamma, -+ double new_gamma ); -+ -+/* From rle_getcom.c. */ -+/***************************************************************** -+ * TAG( rle_getcom ) -+ * -+ * Get a specific comment from the image comments. -+ */ -+const char * -+rle_getcom(const char * const name, -+ rle_hdr * const the_hdr); -+ -+/* From rle_putcom.c. */ -+ -+/* Delete a specific comment from the image comments. */ -+const char * -+rle_delcom(const char * const name, -+ rle_hdr * const the_hdr); -+ -+/* Put (or replace) a comment into the image comments. */ -+const char * -+rle_putcom(const char * const value, -+ rle_hdr * const the_hdr); -+ -+/* From dither.c. */ -+/***************************************************************** -+ * TAG( bwdithermap ) -+ * Create a color map for ordered dithering in grays. -+ */ -+extern void bwdithermap( int levels, double gamma, int bwmap[], -+ int divN[256], int modN[256], int magic[16][16] ); -+/***************************************************************** -+ * TAG( ditherbw ) -+ * Dither a gray-scale value. -+ */ -+extern int ditherbw( int x, int y, int val, -+ int divN[256], int modN[256], int magic[16][16] ); -+/***************************************************************** -+ * TAG( dithergb ) -+ * Dither a color value. -+ */ -+extern int dithergb( int x, int y, int r, int g, int b, -+ int divN[256], int modN[256], int magic[16][16] ); -+/***************************************************************** -+ * TAG( dithermap ) -+ * Create a color map for ordered dithering in color. -+ */ -+extern void dithermap( int levels, double gamma, int rgbmap[][3], -+ int divN[256], int modN[256], int magic[16][16] ); -+/***************************************************************** -+ * TAG( make_square ) -+ * Make a 16x16 magic square for ordered dithering. -+ */ -+extern void make_square( double N, int divN[256], int modN[256], -+ int magic[16][16] ); -+ -+/* From float_to_exp.c. */ -+/***************************************************************** -+ * TAG( float_to_exp ) -+ * Convert a list of floating point numbers to "exp" format. -+ */ -+extern void float_to_exp( int count, float * floats, rle_pixel * pixels ); -+ -+/* From rle_open_f.c. */ -+/***************************************************************** -+ * TAG( rle_open_f ) -+ * -+ * Open an input/output file with default. -+ */ -+FILE * -+rle_open_f(const char * prog_name, const char * file_name, -+ const char * mode); -+ -+/***************************************************************** -+ * TAG( rle_open_f_noexit ) -+ * -+ * Open an input/output file with default. -+ */ -+FILE * -+rle_open_f_noexit(const char * const prog_name, -+ const char * const file_name, -+ const char * const mode); -+ -+/***************************************************************** -+ * TAG( rle_close_f ) -+ * -+ * Close a file opened by rle_open_f. If the file is stdin or stdout, -+ * it will not be closed. -+ */ -+extern void -+rle_close_f( FILE *fd ); -+ -+/* From colorquant.c. */ -+/***************************************************************** -+ * TAG( colorquant ) -+ * Compute a colormap for quantizing an image to a limited set of colors. -+ */ -+extern int colorquant( rle_pixel *red, rle_pixel *green, rle_pixel *blue, -+ unsigned long pixels, rle_pixel *colormap[3], -+ int colors, int bits, -+ rle_pixel *rgbmap, int fast, int otherimages ); -+ -+/* From rle_addhist.c. */ -+ -+/* Append history information to the HISTORY comment. */ -+void -+rle_addhist(char * argv[], -+ rle_hdr * const in_hdr, -+ rle_hdr * const out_hdr); -+ -+/* From cmd_name.c. */ -+/***************************************************************** -+ * TAG( cmd_name ) -+ * Extract command name from argv. -+ */ -+extern char *cmd_name( char **argv ); -+ -+/* From scanargs.c. */ -+/***************************************************************** -+ * TAG( scanargs ) -+ * Scan command argument list and parse arguments. -+ */ -+extern int scanargs( int argc, -+ char **argv, -+ const char *format, -+ ... ); -+ -+/* From hilbert.c */ -+/***************************************************************** -+ * TAG( hilbert_i2c ) -+ * Convert an index into a Hilbert curve to a set of coordinates. -+ */ -+extern void hilbert_c2i( int n, int m, int a[], long int *r ); -+ -+/***************************************************************** -+ * TAG( hilbert_c2i ) -+ * Convert coordinates of a point on a Hilbert curve to its index. -+ */ -+extern void hilbert_i2c( int n, int m, long int r, int a[] ); -+ -+/* From inv_cmap.c */ -+/***************************************************************** -+ * TAG( inv_cmap ) -+ * Compute an inverse colormap efficiently. -+ */ -+extern void inv_cmap( int colors, -+ unsigned char *colormap[3], -+ int bits, -+ unsigned long *dist_buf, -+ unsigned char *rgbmap ); -+ -+#endif /* RLE_H */ -diff -urNp a/urt/rle_open_f.c b/urt/rle_open_f.c ---- a/urt/rle_open_f.c 2019-12-06 09:04:58.740176020 +0100 -+++ b/urt/rle_open_f.c 2019-12-06 08:38:15.114037944 +0100 -@@ -163,65 +163,7 @@ dealWithSubprocess(const char * const f +diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c +index ae8548b..c2ef37d 100644 +--- a/urt/rle_open_f.c ++++ b/urt/rle_open_f.c +@@ -163,65 +163,7 @@ dealWithSubprocess(const char * const file_name, FILE ** const fpP, bool * const noSubprocessP, const char ** const errorP) { @@ -5319,9 +5425,10 @@ diff -urNp a/urt/rle_open_f.c b/urt/rle_open_f.c } -diff -urNp a/urt/rle_putcom.c b/urt/rle_putcom.c ---- a/urt/rle_putcom.c 2019-12-06 09:04:58.740176020 +0100 -+++ b/urt/rle_putcom.c 2019-12-06 08:38:15.114037944 +0100 +diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c +index ab2eb20..ce83615 100644 +--- a/urt/rle_putcom.c ++++ b/urt/rle_putcom.c @@ -98,12 +98,14 @@ rle_putcom(const char * const value, const char * v; const char ** old_comments; @@ -5338,37 +5445,10 @@ diff -urNp a/urt/rle_putcom.c b/urt/rle_putcom.c /* Not found */ /* Can't realloc because somebody else might be pointing to this * comments block. Of course, if this were true, then the -diff -urNp a/urt/Runput.c b/urt/Runput.c ---- a/urt/Runput.c 2019-12-06 09:04:58.741176029 +0100 -+++ b/urt/Runput.c 2019-12-06 08:38:15.113037935 +0100 -@@ -202,10 +202,11 @@ RunSetup(rle_hdr * the_hdr) - if ( the_hdr->background != 0 ) - { - register int i; -- register rle_pixel *background = -- (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); -- register int *bg_color; -- /* -+ register rle_pixel *background; -+ register int *bg_color; -+ -+ overflow_add(the_hdr->ncolors,1); -+ background = (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); /* - * If even number of bg color bytes, put out one more to get to - * 16 bit boundary. - */ -@@ -224,7 +225,7 @@ RunSetup(rle_hdr * the_hdr) - /* Big-endian machines are harder */ - register int i, nmap = (1 << the_hdr->cmaplen) * - the_hdr->ncmap; -- register char *h_cmap = (char *)malloc( nmap * 2 ); -+ register char *h_cmap = (char *)malloc2( nmap, 2 ); - if ( h_cmap == NULL ) - { - fprintf( stderr, -diff -urNp a/urt/scanargs.c b/urt/scanargs.c ---- a/urt/scanargs.c 2019-12-06 09:04:58.740176020 +0100 -+++ b/urt/scanargs.c 2019-12-06 08:38:15.115037953 +0100 +diff --git a/urt/scanargs.c b/urt/scanargs.c +index f3af334..5e114bb 100644 +--- a/urt/scanargs.c ++++ b/urt/scanargs.c @@ -62,9 +62,8 @@ typedef int *ptr; /* * Storage allocation macros