mark%zok@sj.ate.slb.com (Mark W. Snitily) (05/30/90)
Posting-number: Volume 13, Issue 17 Submitted-by: mark%zok@sj.ate.slb.com (Mark W. Snitily) Archive-name: ppmtoxpm.p1 Brandon, The following is a patch which corrects a malloc argument bug in ppmtoxpm (v10i079). Classic case of when an "i" should have been a "j". -- Mark Mark W. Snitily Consulting Services: 894 Brookgrove Lane Graphics, Operating Systems, Compilers Cupertino, CA 95014 (408) 252-0456 mark@zok.uucp *** ppmtoxpm.c.org Wed Feb 14 16:42:43 1990 --- ppmtoxpm.c Tue May 29 00:14:16 1990 *************** *** 13,18 **** --- 13,20 ---- ** with their permission is being made available to the public with the above ** copyright notice and permission notice. ** + ** 28-May-90 MWS Corrected malloc argument bug in routine gen_cmap(). + ** */ #include <stdio.h> *************** *** 285,291 **** /* Allocate memory for printed number. Abort if error. */ if (!(str = (char *) malloc(digits+1))) ! pm_error("out of memory", 0, 0, 0, 0, 0); /* Generate characters starting with least significant digit. */ p = str + digits; --- 287,293 ---- /* Allocate memory for printed number. Abort if error. */ if (!(str = (char *) malloc(digits+1))) ! pm_error("out of memory allocating number string", 0, 0, 0, 0, 0); /* Generate characters starting with least significant digit. */ p = str + digits; *************** *** 382,389 **** if (r == rgbn[j].r && g == rgbn[j].g && b == rgbn[j].b) { /* Matched. Allocate string, copy mnemonic, and exit. */ ! if (!(str = (char *) malloc(strlen(rgbn[i].name)+1))) ! pm_error("out of memory", 0, 0, 0, 0, 0); strcpy(str, rgbn[j].name); cmap[i].rgbname = str; matched = 1; --- 384,392 ---- if (r == rgbn[j].r && g == rgbn[j].g && b == rgbn[j].b) { /* Matched. Allocate string, copy mnemonic, and exit. */ ! if (!(str = (char *) malloc(strlen(rgbn[j].name)+1))) ! pm_error("out of memory allocating color mnemonic", ! 0, 0, 0, 0, 0); strcpy(str, rgbn[j].name); cmap[i].rgbname = str; matched = 1; *************** *** 398,404 **** mval == 0x00FF ? 8 : mval == 0x0FFF ? 11 : 14))) ! pm_error("out of memory", 0, 0, 0, 0, 0); sprintf(str, mval == 0x000F ? "#%X%X%X" : mval == 0x00FF ? "#%02X%02X%02X" : --- 401,407 ---- mval == 0x00FF ? 8 : mval == 0x0FFF ? 11 : 14))) ! pm_error("out of memory allocating absolute RGB", 0, 0, 0, 0, 0); sprintf(str, mval == 0x000F ? "#%X%X%X" : mval == 0x00FF ? "#%02X%02X%02X" :