View | Details | Raw Unified
Collapse All | Expand All

(-) motif/lib/Xm/Xpmparse.c.XPM (-23 / +119 lines)
 Lines 93-99    Link Here 
LFUNC(ScanTransparentColor, int, (XpmColor *color, unsigned int cpp,
LFUNC(ScanTransparentColor, int, (XpmColor *color, unsigned int cpp,
				  XpmAttributes *attributes));
				  XpmAttributes *attributes));
LFUNC(ScanOtherColors, int, (Display *display, XpmColor *colors, int ncolors,
LFUNC(ScanOtherColors, int, (Display *display, XpmColor *colors, 
			     unsigned int ncolors, 
			     Pixel *pixels, unsigned int mask,
			     Pixel *pixels, unsigned int mask,
			     unsigned int cpp, XpmAttributes *attributes));
			     unsigned int cpp, XpmAttributes *attributes));
 Lines 220-230    Link Here 
    else
    else
	cpp = 0;
	cpp = 0;
    if ((height > 0 && width >= SIZE_MAX / height) ||
	width * height >= SIZE_MAX / sizeof(unsigned int))
	RETURN(XpmNoMemory);
    pmap.pixelindex =
    pmap.pixelindex =
	(unsigned int *) XpmCalloc(width * height, sizeof(unsigned int));
	(unsigned int *) XpmCalloc(width * height, sizeof(unsigned int));
    if (!pmap.pixelindex)
    if (!pmap.pixelindex)
	RETURN(XpmNoMemory);
	RETURN(XpmNoMemory);
    if (pmap.size >= SIZE_MAX / sizeof(Pixel)) 
	RETURN(XpmNoMemory);
    pmap.pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * pmap.size);
    pmap.pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * pmap.size);
    if (!pmap.pixels)
    if (!pmap.pixels)
	RETURN(XpmNoMemory);
	RETURN(XpmNoMemory);
 Lines 279-285    Link Here 
     * get rgb values and a string of char, and possibly a name for each
     * get rgb values and a string of char, and possibly a name for each
     * color
     * color
     */
     */
    if (pmap.ncolors >= SIZE_MAX / sizeof(XpmColor))
	RETURN(XpmNoMemory);
    colorTable = (XpmColor *) XpmCalloc(pmap.ncolors, sizeof(XpmColor));
    colorTable = (XpmColor *) XpmCalloc(pmap.ncolors, sizeof(XpmColor));
    if (!colorTable)
    if (!colorTable)
	RETURN(XpmNoMemory);
	RETURN(XpmNoMemory);
 Lines 327-332    Link Here 
    /* first get a character string */
    /* first get a character string */
    a = 0;
    a = 0;
    if (cpp >= SIZE_MAX - 1)
	return (XpmNoMemory);
    if (!(s = color->string = (char *) XpmMalloc(cpp + 1)))
    if (!(s = color->string = (char *) XpmMalloc(cpp + 1)))
	return (XpmNoMemory);
	return (XpmNoMemory);
    *s++ = printable[c = a % MAXPRINTABLE];
    *s++ = printable[c = a % MAXPRINTABLE];
 Lines 374-380    Link Here 
ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)
    Display *display;
    Display *display;
    XpmColor *colors;
    XpmColor *colors;
    int ncolors;
    unsigned int ncolors;
    Pixel *pixels;
    Pixel *pixels;
    unsigned int mask;
    unsigned int mask;
    unsigned int cpp;
    unsigned int cpp;
 Lines 418-423    Link Here 
    }
    }
    /* first get character strings and rgb values */
    /* first get character strings and rgb values */
    if (ncolors >= SIZE_MAX / sizeof(XColor) || cpp >= SIZE_MAX - 1)
	return (XpmNoMemory);
    xcolors = (XColor *) XpmMalloc(sizeof(XColor) * ncolors);
    xcolors = (XColor *) XpmMalloc(sizeof(XColor) * ncolors);
    if (!xcolors)
    if (!xcolors)
	return (XpmNoMemory);
	return (XpmNoMemory);
 Lines 239-244    Link Here 
    unsigned int x, y, h;
    unsigned int x, y, h;
    h = height - 1;
    h = height - 1;
    if (cpp != 0 && width >= (SIZE_MAX - 3)/cpp) 
	return XpmNoMemory;    
    p = buf = (char *) XpmMalloc(width * cpp + 3);
    p = buf = (char *) XpmMalloc(width * cpp + 3);
    if (!buf)
    if (!buf)
	return (XpmNoMemory);
	return (XpmNoMemory);
 Lines 136-142    Link Here 
    xpmHashTable *table;
    xpmHashTable *table;
{
{
    xpmHashAtom *atomTable = table->atomTable;
    xpmHashAtom *atomTable = table->atomTable;
    int size = table->size;
    unsigned int size = table->size;
    xpmHashAtom *t, *p;
    xpmHashAtom *t, *p;
    int i;
    int i;
    int oldSize = size;
    int oldSize = size;
 Lines 145-150    Link Here 
    HASH_TABLE_GROWS
    HASH_TABLE_GROWS
	table->size = size;
	table->size = size;
    table->limit = size / 3;
    table->limit = size / 3;
    if (size >= SIZE_MAX / sizeof(*atomTable)) 
	return (XpmNoMemory);
    atomTable = (xpmHashAtom *) XpmMalloc(size * sizeof(*atomTable));
    atomTable = (xpmHashAtom *) XpmMalloc(size * sizeof(*atomTable));
    if (!atomTable)
    if (!atomTable)
	return (XpmNoMemory);
	return (XpmNoMemory);
 Lines 205-210    Link Here 
    table->size = INITIAL_HASH_SIZE;
    table->size = INITIAL_HASH_SIZE;
    table->limit = table->size / 3;
    table->limit = table->size / 3;
    table->used = 0;
    table->used = 0;
    if (table->size >= SIZE_MAX / sizeof(*atomTable))
	return (XpmNoMemory);
    atomTable = (xpmHashAtom *) XpmMalloc(table->size * sizeof(*atomTable));
    atomTable = (xpmHashAtom *) XpmMalloc(table->size * sizeof(*atomTable));
    if (!atomTable)
    if (!atomTable)
	return (XpmNoMemory);
	return (XpmNoMemory);
 Lines 129-134    Link Here 
     */
     */
    header_nlines = 1 + image->ncolors;
    header_nlines = 1 + image->ncolors;
    header_size = sizeof(char *) * header_nlines;
    header_size = sizeof(char *) * header_nlines;
    if (header_size >= SIZE_MAX / sizeof(char *))
	return (XpmNoMemory);
    header = (char **) XpmCalloc(header_size, sizeof(char *));
    header = (char **) XpmCalloc(header_size, sizeof(char *));
    if (!header)
    if (!header)
	return (XpmNoMemory);
	return (XpmNoMemory);
 Lines 179-184    Link Here 
		boundCheckingCalloc((long)(nelem),(long) (elsize))
		boundCheckingCalloc((long)(nelem),(long) (elsize))
#endif
#endif
#if defined(SCO) || defined(__USLC__)
#include <stdint.h>	/* For SIZE_MAX */
#endif
#include <limits.h>
#ifndef SIZE_MAX
# ifdef ULONG_MAX
#  define SIZE_MAX ULONG_MAX
# else 
#  define SIZE_MAX UINT_MAX
# endif
#endif
#define XPMMAXCMTLEN BUFSIZ
#define XPMMAXCMTLEN BUFSIZ
typedef struct {
typedef struct {
    unsigned int type;
    unsigned int type;
 Lines 276-284    Link Here 
}      *xpmHashAtom;
}      *xpmHashAtom;
typedef struct {
typedef struct {
    int size;
    unsigned int size;
    int limit;
    unsigned int limit;
    int used;
    unsigned int used;
    xpmHashAtom *atomTable;
    xpmHashAtom *atomTable;
}      xpmHashTable;
}      xpmHashTable;
 Lines 799-804    Link Here 
    ErrorStatus = XpmSuccess;
    ErrorStatus = XpmSuccess;
    if (image->ncolors >= SIZE_MAX / sizeof(Pixel)) 
	return (XpmNoMemory);
    /* malloc pixels index tables */
    /* malloc pixels index tables */
    image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
    image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);
    if (!image_pixels)
    if (!image_pixels)
 Lines 942-947    Link Here 
	return (XpmNoMemory);
	return (XpmNoMemory);
#ifndef FOR_MSW
#ifndef FOR_MSW
    if (height != 0 && (*image_return)->bytes_per_line >= SIZE_MAX / height)
      return XpmNoMemory;
    /* now that bytes_per_line must have been set properly alloc data */
    /* now that bytes_per_line must have been set properly alloc data */
    (*image_return)->data =
    (*image_return)->data =
	(char *) XpmMalloc((*image_return)->bytes_per_line * height);
	(char *) XpmMalloc((*image_return)->bytes_per_line * height);
 Lines 1987-1992    Link Here 
	xpmGetCmt(data, &colors_cmt);
	xpmGetCmt(data, &colors_cmt);
    /* malloc pixels index tables */
    /* malloc pixels index tables */
    if (ncolors >= SIZE_MAX / sizeof(Pixel)) 
	return XpmNoMemory;
    image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
    image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
    if (!image_pixels)
    if (!image_pixels)
	RETURN(XpmNoMemory);
	RETURN(XpmNoMemory);
 Lines 2200-2205    Link Here 
	{
	{
	    unsigned short colidx[256];
	    unsigned short colidx[256];
	    if (ncolors > 256)
		return (XpmFileInvalid);
	    bzero((char *)colidx, 256 * sizeof(short));
	    bzero((char *)colidx, 256 * sizeof(short));
	    for (a = 0; a < ncolors; a++)
	    for (a = 0; a < ncolors; a++)
		colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
		colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
 Lines 2242-2247    Link Here 
	    unsigned short *cidx[256];
	    unsigned short *cidx[256];
	    int char1;
	    int char1;
	    if (ncolors > 256)
		return (XpmFileInvalid);
	    bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
	    bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
	    for (a = 0; a < ncolors; a++) {
	    for (a = 0; a < ncolors; a++) {
		char1 = colorTable[a].string[0];
		char1 = colorTable[a].string[0];
 Lines 2298-2303    Link Here 
	    char *s;
	    char *s;
	    char buf[BUFSIZ];
	    char buf[BUFSIZ];
	    if (cpp >= sizeof(buf))
		return (XpmFileInvalid);
	    buf[cpp] = '\0';
	    buf[cpp] = '\0';
	    if (USE_HASHTABLE) {
	    if (USE_HASHTABLE) {
		xpmHashAtom *slot;
		xpmHashAtom *slot;
 Lines 36-42    Link Here 
#include "XpmI.h"
#include "XpmI.h"
/* 3.2 backward compatibility code */
/* 3.2 backward compatibility code */
LFUNC(CreateOldColorTable, int, (XpmColor *ct, int ncolors,
LFUNC(CreateOldColorTable, int, (XpmColor *ct, unsigned int ncolors,
				 XpmColor ***oldct));
				 XpmColor ***oldct));
LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, int ncolors));
LFUNC(FreeOldColorTable, void, (XpmColor **colorTable, int ncolors));
 Lines 47-58    Link Here 
static int
static int
CreateOldColorTable(ct, ncolors, oldct)
CreateOldColorTable(ct, ncolors, oldct)
    XpmColor *ct;
    XpmColor *ct;
    int ncolors;
    unsigned int ncolors;
    XpmColor ***oldct;
    XpmColor ***oldct;
{
{
    XpmColor **colorTable, **color;
    XpmColor **colorTable, **color;
    int a;
    int a;
    if (ncolors >= SIZE_MAX / sizeof(XpmColor *)) 
	return XpmNoMemory;
    colorTable = (XpmColor **) XpmMalloc(ncolors * sizeof(XpmColor *));
    colorTable = (XpmColor **) XpmMalloc(ncolors * sizeof(XpmColor *));
    if (!colorTable) {
    if (!colorTable) {
	*oldct = NULL;
	*oldct = NULL;
 Lines 72-78    Link Here 
    LINTLIBS = $(LINTXLIB) $(LINTXTOOL)
    LINTLIBS = $(LINTXLIB) $(LINTXTOOL)
     DEFINES = XmDefines StrcasecmpDefines
     DEFINES = XmDefines StrcasecmpDefines $(STRLCATDEF)
SRCH_DEFINES = -DLIBDIR=\"$(XPROJECTROOT)/lib/X11\" -DINCDIR=\"$(XPROJECTROOT)/include/X11\"
SRCH_DEFINES = -DLIBDIR=\"$(XPROJECTROOT)/lib/X11\" -DINCDIR=\"$(XPROJECTROOT)/include/X11\"
BINDINGS_DEF = -DXMBINDDIR_FALLBACK=\"VirtualBindingsPath\"
BINDINGS_DEF = -DXMBINDDIR_FALLBACK=\"VirtualBindingsPath\"
STRINGSABIOPTIONS = ToolkitStringsABIOptions
STRINGSABIOPTIONS = ToolkitStringsABIOptions
 Lines 258-263    Link Here 
UNSHAREDOBJS = XmStrDefs.o sharedlib.o
UNSHAREDOBJS = XmStrDefs.o sharedlib.o
#endif
#endif
#if HasStrlcat
STRLCATDEF = -DHAS_STRLCAT
#endif
#define LibTookitMakeStringsDependency	YES
#define LibTookitMakeStringsDependency	YES
#include <Library.tmpl>
#include <Library.tmpl>
 Lines 42-47    Link Here 
#include "XpmI.h"
#include "XpmI.h"
#include <ctype.h>
#include <ctype.h>
#ifdef HAS_STRLCAT
# define STRLCAT(dst, src, dstsize) { \
  	if (strlcat(dst, src, dstsize) >= (dstsize)) \
	    return (XpmFileInvalid); }
# define STRLCPY(dst, src, dstsize) { \
  	if (strlcpy(dst, src, dstsize) >= (dstsize)) \
	    return (XpmFileInvalid); }
#else
# define STRLCAT(dst, src, dstsize) { \
	if ((strlen(dst) + strlen(src)) < (dstsize)) \
 	    strcat(dst, src); \
	else return (XpmFileInvalid); }
# define STRLCPY(dst, src, dstsize) { \
	if (strlen(src) < (dstsize)) \
 	    strcpy(dst, src); \
	else return (XpmFileInvalid); }
#endif
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width,
LFUNC(ParsePixels, int, (xpmData *data, unsigned int width,
			 unsigned int height, unsigned int ncolors,
			 unsigned int height, unsigned int ncolors,
			 unsigned int cpp, XpmColor *colorTable,
			 unsigned int cpp, XpmColor *colorTable,
 Lines 209-215    Link Here 
    unsigned int *extensions;
    unsigned int *extensions;
{
{
    unsigned int l;
    unsigned int l;
    char buf[BUFSIZ];
    char buf[BUFSIZ + 1];
    if (!data->format) {		/* XPM 2 or 3 */
    if (!data->format) {		/* XPM 2 or 3 */
 Lines 318-327    Link Here 
    XpmColor **colorTablePtr;
    XpmColor **colorTablePtr;
    xpmHashTable *hashtable;
    xpmHashTable *hashtable;
{
{
    unsigned int key, l, a, b;
    unsigned int key = 0, l, a, b, len;
    unsigned int curkey;		/* current color key */
    unsigned int curkey;		/* current color key */
    unsigned int lastwaskey;		/* key read */
    unsigned int lastwaskey;		/* key read */
    char buf[BUFSIZ];
    char buf[BUFSIZ+1];
    char curbuf[BUFSIZ];		/* current buffer */
    char curbuf[BUFSIZ];		/* current buffer */
    char **sptr, *s;
    char **sptr, *s;
    XpmColor *color;
    XpmColor *color;
 Lines 329-334    Link Here 
    char **defaults;
    char **defaults;
    int ErrorStatus;
    int ErrorStatus;
    if (ncolors >= SIZE_MAX / sizeof(XpmColor))
	return (XpmNoMemory);
    colorTable = (XpmColor *) XpmCalloc(ncolors, sizeof(XpmColor));
    colorTable = (XpmColor *) XpmCalloc(ncolors, sizeof(XpmColor));
    if (!colorTable)
    if (!colorTable)
	return (XpmNoMemory);
	return (XpmNoMemory);
 Lines 340-345    Link Here 
	    /*
	    /*
	     * read pixel value
	     * read pixel value
	     */
	     */
	    if (cpp >= SIZE_MAX - 1) {
		xpmFreeColorTable(colorTable, ncolors);
		return (XpmNoMemory);
	    }
	    color->string = (char *) XpmMalloc(cpp + 1);
	    color->string = (char *) XpmMalloc(cpp + 1);
	    if (!color->string) {
	    if (!color->string) {
		xpmFreeColorTable(colorTable, ncolors);
		xpmFreeColorTable(colorTable, ncolors);
 Lines 377-389    Link Here 
		}
		}
		if (!lastwaskey && key < NKEYS) {	/* open new key */
		if (!lastwaskey && key < NKEYS) {	/* open new key */
		    if (curkey) {	/* flush string */
		    if (curkey) {	/* flush string */
			s = (char *) XpmMalloc(strlen(curbuf) + 1);
			len = strlen(curbuf) + 1;
			s = (char *) XpmMalloc(len);
			if (!s) {
			if (!s) {
			    xpmFreeColorTable(colorTable, ncolors);
			    xpmFreeColorTable(colorTable, ncolors);
			    return (XpmNoMemory);
			    return (XpmNoMemory);
			}
			}
			defaults[curkey] = s;
			defaults[curkey] = s;
			strcpy(s, curbuf);
			memcpy(s, curbuf, len);
		    }
		    }
		    curkey = key + 1;	/* set new key  */
		    curkey = key + 1;	/* set new key  */
		    *curbuf = '\0';	/* reset curbuf */
		    *curbuf = '\0';	/* reset curbuf */
 Lines 394-402    Link Here 
			return (XpmFileInvalid);
			return (XpmFileInvalid);
		    }
		    }
		    if (!lastwaskey)
		    if (!lastwaskey)
			strcat(curbuf, " ");	/* append space */
			STRLCAT(curbuf, " ", sizeof(curbuf)); /* append space */
		    buf[l] = '\0';
		    buf[l] = '\0';
		    strcat(curbuf, buf);/* append buf */
		    STRLCAT(curbuf, buf, sizeof(curbuf));/* append buf */
		    lastwaskey = 0;
		    lastwaskey = 0;
		}
		}
	    }
	    }
 Lines 404-415    Link Here 
		xpmFreeColorTable(colorTable, ncolors);
		xpmFreeColorTable(colorTable, ncolors);
		return (XpmFileInvalid);
		return (XpmFileInvalid);
	    }
	    }
	    s = defaults[curkey] = (char *) XpmMalloc(strlen(curbuf) + 1);
	    len = strlen(curbuf) + 1;
	    s = defaults[curkey] = (char *) XpmMalloc(len);
	    if (!s) {
	    if (!s) {
		xpmFreeColorTable(colorTable, ncolors);
		xpmFreeColorTable(colorTable, ncolors);
		return (XpmNoMemory);
		return (XpmNoMemory);
	    }
	    }
	    strcpy(s, curbuf);
	    memcpy(s, curbuf, len);
	}
	}
    } else {				/* XPM 1 */
    } else {				/* XPM 1 */
	/* get to the beginning of the first string */
	/* get to the beginning of the first string */
 Lines 422-427    Link Here 
	    /*
	    /*
	     * read pixel value
	     * read pixel value
	     */
	     */
	    if (cpp >= SIZE_MAX - 1) {
		xpmFreeColorTable(colorTable, ncolors);
		return (XpmNoMemory);
	    }
	    color->string = (char *) XpmMalloc(cpp + 1);
	    color->string = (char *) XpmMalloc(cpp + 1);
	    if (!color->string) {
	    if (!color->string) {
		xpmFreeColorTable(colorTable, ncolors);
		xpmFreeColorTable(colorTable, ncolors);
 Lines 450-465    Link Here 
	    *curbuf = '\0';		/* init curbuf */
	    *curbuf = '\0';		/* init curbuf */
	    while (l = xpmNextWord(data, buf, BUFSIZ)) {
	    while (l = xpmNextWord(data, buf, BUFSIZ)) {
		if (*curbuf != '\0')
		if (*curbuf != '\0')
		    strcat(curbuf, " ");/* append space */
		    STRLCAT(curbuf, " ", sizeof(curbuf));/* append space */
		buf[l] = '\0';
		buf[l] = '\0';
		strcat(curbuf, buf);	/* append buf */
		STRLCAT(curbuf, buf, sizeof(curbuf));	/* append buf */
	    }
	    }
	    s = (char *) XpmMalloc(strlen(curbuf) + 1);
	    len = strlen(curbuf) + 1;
	    s = (char *) XpmMalloc(len);
	    if (!s) {
	    if (!s) {
		xpmFreeColorTable(colorTable, ncolors);
		xpmFreeColorTable(colorTable, ncolors);
		return (XpmNoMemory);
		return (XpmNoMemory);
	    }
	    }
	    strcpy(s, curbuf);
	    memcpy(s, curbuf, len);
	    color->c_color = s;
	    color->c_color = s;
	    *curbuf = '\0';		/* reset curbuf */
	    *curbuf = '\0';		/* reset curbuf */
	    if (a < ncolors - 1)
	    if (a < ncolors - 1)
 Lines 484-489    Link Here 
    unsigned int *iptr, *iptr2;
    unsigned int *iptr, *iptr2;
    unsigned int a, x, y;
    unsigned int a, x, y;
    if ((height > 0 && width >= SIZE_MAX / height) ||
	width * height >= SIZE_MAX / sizeof(unsigned int)) 
	return XpmNoMemory;
#ifndef FOR_MSW
#ifndef FOR_MSW
    iptr2 = (unsigned int *) XpmMalloc(sizeof(unsigned int) * width * height);
    iptr2 = (unsigned int *) XpmMalloc(sizeof(unsigned int) * width * height);
#else
#else
 Lines 507-512    Link Here 
	{
	{
	    unsigned short colidx[256];
	    unsigned short colidx[256];
	    if (ncolors > 256)
		return (XpmFileInvalid);
	    bzero((char *)colidx, 256 * sizeof(short));
	    bzero((char *)colidx, 256 * sizeof(short));
	    for (a = 0; a < ncolors; a++)
	    for (a = 0; a < ncolors; a++)
		colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
		colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
 Lines 584-589    Link Here 
	    char *s;
	    char *s;
	    char buf[BUFSIZ];
	    char buf[BUFSIZ];
	    if (cpp >= sizeof(buf))
		return (XpmFileInvalid);
	    buf[cpp] = '\0';
	    buf[cpp] = '\0';
	    if (USE_HASHTABLE) {
	    if (USE_HASHTABLE) {
		xpmHashAtom *slot;
		xpmHashAtom *slot;