From e6e30e94b1da12d0a3247db3b25311bafb8230e6 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 9 Aug 2019 03:06:48 +0000 Subject: Remove RLE_CHECK_ALLOC and rle_alloc_error from URT library. This fixes a wild pointer dereference as well as cleans up code git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3656 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/rletopnm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'converter/other/rletopnm.c') diff --git a/converter/other/rletopnm.c b/converter/other/rletopnm.c index 73ab2659..97f271dc 100644 --- a/converter/other/rletopnm.c +++ b/converter/other/rletopnm.c @@ -274,11 +274,15 @@ writePpmRaster(FILE * const imageoutFileP, alpharow = pgm_allocrow(width); MALLOCARRAY(scanlines, height); - RLE_CHECK_ALLOC( hdr.cmd, scanlines, "scanline pointers" ); + if (!scanlines) + pm_error("Failed to allocate memory for %u scanline pointers", height); - for ( scan = 0; scan < height; scan++ ) - RLE_CHECK_ALLOC( hdr.cmd, (rle_row_alloc(&hdr, &scanlines[scan]) >= 0), - "pixel memory" ); + for (scan = 0; scan < height; ++scan) { + int rc; + rc = rle_row_alloc(&hdr, &scanlines[scan]); + if (rc < 0) + pm_error("Failed to allocate memory for a scanline"); + } /* * Loop through those scan lines. */ @@ -375,11 +379,15 @@ writePgmRaster(FILE * const imageoutFileP, alpharow = pgm_allocrow(width); MALLOCARRAY(scanlines, height); - RLE_CHECK_ALLOC( hdr.cmd, scanlines, "scanline pointers" ); + if (!scanlines) + pm_error("Failed to allocate memory for %u scanline pointers", height); - for (scan = 0; scan < height; ++scan) - RLE_CHECK_ALLOC(hdr.cmd, (rle_row_alloc(&hdr, &scanlines[scan]) >= 0), - "pixel memory" ); + for (scan = 0; scan < height; ++scan) { + int rc; + rc = rle_row_alloc(&hdr, &scanlines[scan]); + if (rc < 0) + pm_error("Failed to allocate memory for a scanline"); + } /* * Loop through those scan lines. */ -- cgit 1.4.1