Commit 6d1dc1f6 authored by Alan Coopersmith's avatar Alan Coopersmith 🛫

Convert main src directory to use reallocarray()

parent bcf7b5aa
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <stdio.h>
/*
......@@ -49,7 +50,7 @@ int *XListDepths (
register Depth *dp;
register int i;
depths = Xmalloc (count * sizeof(int));
depths = Xmallocarray (count, sizeof(int));
if (!depths) return NULL;
for (i = 0, dp = scr->depths; i < count; i++, dp++)
depths[i] = dp->depth;
......
......@@ -63,6 +63,7 @@ from The Open Group.
#include "Xlcint.h"
#include <ctype.h>
#include <X11/Xos.h>
#include "reallocarray.h"
#define XMAXLIST 256
......@@ -112,7 +113,7 @@ _XParseBaseFontNameList(
if (!*ptr)
break;
}
if (!(list = Xmalloc(sizeof(char *) * (*num + 1)))) {
if (!(list = Xmallocarray((*num + 1), sizeof(char *)))) {
Xfree(psave);
return (char **)NULL;
}
......@@ -133,7 +134,7 @@ copy_string_list(
if (string_list == NULL || list_count <= 0)
return (char **) NULL;
string_list_ret = Xmalloc(sizeof(char *) * list_count);
string_list_ret = Xmallocarray(list_count, sizeof(char *));
if (string_list_ret == NULL)
return (char **) NULL;
......
......@@ -31,6 +31,7 @@ authorization from the X Consortium and the XFree86 Project.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
#if defined(XF86BIGFONT)
......@@ -245,8 +246,8 @@ _XQueryFont (
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
size_t pbytes = reply.nFontProps * sizeof(XFontProp);
fs->properties = Xmalloc (pbytes);
fs->properties = Xmallocarray (reply.nFontProps,
sizeof(XFontProp));
}
if (! fs->properties) {
Xfree(fs);
......@@ -266,8 +267,8 @@ _XQueryFont (
if (reply.nCharInfos < (INT_MAX / sizeof(XCharStruct))) {
nbytes = reply.nCharInfos * SIZEOF(xCharInfo);
if ((nbytes >> 2) <= reply_left) {
size_t cibytes = reply.nCharInfos * sizeof(XCharStruct);
fs->per_char = Xmalloc (cibytes);
fs->per_char = Xmallocarray (reply.nCharInfos,
sizeof(XCharStruct));
}
}
if (! fs->per_char) {
......@@ -489,8 +490,8 @@ _XF86BigfontQueryFont (
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
size_t pbytes = reply.nFontProps * sizeof(XFontProp);
fs->properties = Xmalloc (pbytes);
fs->properties = Xmallocarray (reply.nFontProps,
sizeof(XFontProp));
}
if (! fs->properties) {
Xfree(fs);
......@@ -529,7 +530,8 @@ _XF86BigfontQueryFont (
_XEatDataWords(dpy, reply_left);
return (XFontStruct *)NULL;
}
if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
if (! (fs->per_char = Xmallocarray (reply.nCharInfos,
sizeof(XCharStruct)))) {
Xfree(pUniqCI);
Xfree(fs->properties);
Xfree(fs);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
#if defined(XF86BIGFONT)
......@@ -91,22 +92,22 @@ XFontStruct **info) /* RETURN */
XFontStruct * tmp_finfo;
char ** tmp_flist;
tmp_finfo = Xrealloc (finfo, sizeof(XFontStruct) * size);
tmp_finfo = Xreallocarray (finfo, size, sizeof(XFontStruct));
if (tmp_finfo)
finfo = tmp_finfo;
else
goto badmem;
tmp_flist = Xrealloc (flist, sizeof(char *) * (size+1));
tmp_flist = Xreallocarray (flist, size + 1, sizeof(char *));
if (tmp_flist)
flist = tmp_flist;
else
goto badmem;
}
else {
if (! (finfo = Xmalloc(sizeof(XFontStruct) * size)))
if (! (finfo = Xmallocarray(size, sizeof(XFontStruct))))
goto clearwire;
if (! (flist = Xmalloc(sizeof(char *) * (size+1)))) {
if (! (flist = Xmallocarray(size + 1, sizeof(char *)))) {
Xfree(finfo);
goto clearwire;
}
......@@ -137,8 +138,8 @@ XFontStruct **info) /* RETURN */
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
size_t pbytes = reply.nFontProps * sizeof(XFontProp);
fs->properties = Xmalloc (pbytes);
fs->properties = Xmallocarray (reply.nFontProps,
sizeof(XFontProp));
}
if (! fs->properties)
goto badmem;
......
......@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
char **
......@@ -66,7 +67,7 @@ int *actualCount) /* RETURN */
}
if (rep.nFonts) {
flist = Xmalloc (rep.nFonts * sizeof(char *));
flist = Xmallocarray (rep.nFonts, sizeof(char *));
if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2;
ch = Xmalloc(rlen + 1);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
char **XGetFontPath(
......@@ -49,7 +50,7 @@ char **XGetFontPath(
(void) _XReply (dpy, (xReply *) &rep, 0, xFalse);
if (rep.nPaths) {
flist = Xmalloc(rep.nPaths * sizeof (char *));
flist = Xmallocarray(rep.nPaths, sizeof (char *));
if (rep.length < (INT_MAX >> 2)) {
nbytes = (unsigned long) rep.length << 2;
ch = Xmalloc (nbytes + 1);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
XTimeCoord *XGetMotionEvents(
......@@ -53,7 +54,7 @@ XTimeCoord *XGetMotionEvents(
}
if (rep.nEvents && (rep.nEvents < (INT_MAX / sizeof(XTimeCoord))))
tc = Xmalloc(rep.nEvents * sizeof(XTimeCoord));
tc = Xmallocarray(rep.nEvents, sizeof(XTimeCoord));
if (tc == NULL) {
/* server returned either no events or a bad event count */
*nEvents = 0;
......
......@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
#ifdef MIN /* some systems define this in <sys/param.h> */
......@@ -112,8 +113,7 @@ XGetKeyboardMapping (Display *dpy,
nkeysyms = rep.length;
if (nkeysyms > 0) {
if (nkeysyms < (INT_MAX / sizeof (KeySym))) {
nbytes = nkeysyms * sizeof (KeySym);
mapping = Xmalloc (nbytes);
mapping = Xmallocarray (nkeysyms, sizeof (KeySym));
}
if (! mapping) {
_XEatDataWords(dpy, rep.length);
......
......@@ -33,6 +33,7 @@ from The Open Group.
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include "Xatomtype.h"
#include "reallocarray.h"
#include <X11/Xatom.h>
Status XGetRGBColormaps (
......@@ -99,7 +100,7 @@ Status XGetRGBColormaps (
/*
* allocate array
*/
cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap));
cmaps = Xmallocarray (ncmaps, sizeof (XStandardColormap));
if (!cmaps) {
Xfree (data);
return False;
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
Colormap *XListInstalledColormaps(
register Display *dpy,
......@@ -50,8 +51,7 @@ Colormap *XListInstalledColormaps(
}
if (rep.nColormaps) {
nbytes = rep.nColormaps * sizeof(Colormap);
cmaps = Xmalloc(nbytes);
cmaps = Xmallocarray(rep.nColormaps, sizeof(Colormap));
if (! cmaps) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
Atom *XListProperties(
register Display *dpy,
......@@ -49,8 +50,7 @@ Atom *XListProperties(
}
if (rep.nProperties) {
nbytes = rep.nProperties * sizeof(Atom);
properties = Xmalloc (nbytes);
properties = Xmallocarray (rep.nProperties, sizeof(Atom));
if (! properties) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
char **XListExtensions(
......@@ -54,7 +55,7 @@ char **XListExtensions(
}
if (rep.nExtensions) {
list = Xmalloc (rep.nExtensions * sizeof (char *));
list = Xmallocarray (rep.nExtensions, sizeof (char *));
if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2;
ch = Xmalloc (rlen + 1);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <limits.h>
XModifierKeymap *
......@@ -100,7 +101,7 @@ XNewModifiermap(int keyspermodifier)
if (res) {
res->max_keypermod = keyspermodifier;
res->modifiermap = (keyspermodifier > 0 ?
Xmalloc(8 * keyspermodifier)
Xmallocarray(keyspermodifier, 8)
: (KeyCode *) NULL);
if (keyspermodifier && (res->modifiermap == NULL)) {
Xfree(res);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
#include <stdio.h>
/*
......@@ -39,7 +40,7 @@ XPixmapFormatValues *XListPixmapFormats (
int *count) /* RETURN */
{
XPixmapFormatValues *formats =
Xmalloc(dpy->nformats * sizeof (XPixmapFormatValues));
Xmallocarray(dpy->nformats, sizeof (XPixmapFormatValues));
if (formats) {
register int i;
......
......@@ -55,6 +55,7 @@ SOFTWARE.
#include "Xutil.h"
#include <X11/Xregion.h>
#include "poly.h"
#include "reallocarray.h"
/*
* InsertEdgeInET
......@@ -409,7 +410,7 @@ static int PtsToRegion(
numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
if (!(reg->rects = Xrealloc(reg->rects, sizeof(BOX) * numRects))) {
if (!(reg->rects = Xreallocarray(reg->rects, numRects, sizeof(BOX)))) {
Xfree(prevRects);
return(0);
}
......@@ -519,7 +520,7 @@ XPolygonRegion(
if (Count < 2) return region;
if (! (pETEs = Xmalloc(sizeof(EdgeTableEntry) * Count))) {
if (! (pETEs = Xmallocarray(Count, sizeof(EdgeTableEntry)))) {
XDestroyRegion(region);
return (Region) NULL;
}
......
......@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <stdio.h>
#include "Cr.h"
#include "ImUtil.h"
#include "reallocarray.h"
#if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32))
#define RConst /**/
......@@ -771,7 +772,7 @@ SendZImage(
(req_yoffset * image->bytes_per_line) +
((req_xoffset * image->bits_per_pixel) >> 3);
if ((image->bits_per_pixel == 4) && ((unsigned int) req_xoffset & 0x01)) {
if (! (shifted_src = Xmalloc(req->height * image->bytes_per_line))) {
if (! (shifted_src = Xmallocarray(req->height, image->bytes_per_line))) {
UnGetReq(PutImage);
return;
}
......@@ -991,7 +992,7 @@ XPutImage (
img.bits_per_pixel = dest_bits_per_pixel;
img.bytes_per_line = ROUNDUP((dest_bits_per_pixel * width),
dest_scanline_pad) >> 3;
img.data = Xmalloc(img.bytes_per_line * height);
img.data = Xmallocarray(height, img.bytes_per_line);
if (img.data == NULL)
return 0;
_XInitImageFuncPtrs(&img);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
static void
_XQueryColors(
......@@ -50,9 +51,9 @@ _XQueryColors(
/* XXX this isn't very efficient */
if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
unsigned long nbytes = (long) ncolors * SIZEOF(xrgb);
xrgb *color = Xmalloc(nbytes);
xrgb *color = Xmallocarray(ncolors, sizeof(xrgb));
if (color != NULL) {
unsigned long nbytes = (long) ncolors * SIZEOF(xrgb);
_XRead(dpy, (char *) color, nbytes);
......
......@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
#include "reallocarray.h"
Status XQueryTree (
register Display *dpy,
......@@ -51,8 +52,7 @@ Status XQueryTree (
*children = (Window *) NULL;
if (rep.nChildren != 0) {
nbytes = rep.nChildren * sizeof(Window);
*children = Xmalloc(nbytes);
*children = Xmallocarray(rep.nChildren, sizeof(Window));
if (! *children) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
......
......@@ -55,6 +55,7 @@ from The Open Group.
#include "Xlibint.h"
#include <X11/Xresource.h>
#include "Xresinternal.h"
#include "reallocarray.h"
/* Not cost effective, at least for vanilla MIT clients */
/* #define PERMQ */
......@@ -288,15 +289,15 @@ nomatch: if (!rehash)
q = nextQuark;
if (!(q & QUANTUMMASK)) {
if (!(q & CHUNKMASK)) {
if (!(new = Xrealloc(stringTable,
sizeof(XrmString *) *
((q >> QUANTUMSHIFT) + CHUNKPER))))
if (!(new = Xreallocarray(stringTable,
(q >> QUANTUMSHIFT) + CHUNKPER,
sizeof(XrmString *))))
goto fail;
stringTable = (XrmString **)new;
#ifdef PERMQ
if (!(new = Xrealloc(permTable,
sizeof(Bits *) *
((q >> QUANTUMSHIFT) + CHUNKPER))))
if (!(new = Xreallocarray(permTable,
(q >> QUANTUMSHIFT) + CHUNKPER,
sizeof(Bits *))))
goto fail;
permTable = (Bits **)new;
#endif
......
......@@ -49,7 +49,7 @@ from The Open Group.
#include "Xutil.h"
#include <stdio.h>
#include <ctype.h>
#include "reallocarray.h"
#define MAX_SIZE 255
......@@ -190,10 +190,10 @@ XReadBitmapFileData (
bytes_per_line = (ww+7)/8 + padding;
size = bytes_per_line * hh;
bits = Xmalloc (size);
bits = Xmallocarray (hh, bytes_per_line);
if (!bits)
RETURN (BitmapNoMemory);
size = bytes_per_line * hh;
if (version10p) {
unsigned char *ptr;
......
......@@ -77,6 +77,7 @@ SOFTWARE.
#include "Xutil.h"
#include <X11/Xregion.h>
#include "poly.h"
#include "reallocarray.h"
#ifdef DEBUG
#include <stdio.h>
......@@ -521,8 +522,8 @@ miRegionCopy(
{
BOX *prevRects = dstrgn->rects;
dstrgn->rects = Xrealloc(dstrgn->rects,
rgn->numRects * (sizeof(BOX)));
dstrgn->rects = Xreallocarray(dstrgn->rects,
rgn->numRects, sizeof(BOX));
if (! dstrgn->rects) {
Xfree(prevRects);
dstrgn->size = 0;
......@@ -790,7 +791,7 @@ miRegionOp(
*/
newReg->size = max(reg1->numRects,reg2->numRects) * 2;
if (! (newReg->rects = Xmalloc (sizeof(BoxRec) * newReg->size))) {
if (! (newReg->rects = Xmallocarray (newReg->size, sizeof(BoxRec)))) {
newReg->size = 0;
return;
}
......@@ -980,8 +981,8 @@ miRegionOp(
if (REGION_NOT_EMPTY(newReg))
{
BoxPtr prev_rects = newReg->rects;
newReg->rects = Xrealloc (newReg->rects,
sizeof(BoxRec) * newReg->numRects);
newReg->rects = Xreallocarray (newReg->rects,
newReg->numRects, sizeof(BoxRec));
if (! newReg->rects)
newReg->rects = prev_rects;
else
......
......@@ -54,6 +54,7 @@ SOFTWARE.
#include "Xatomtype.h"
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include "reallocarray.h"
#define safestrlen(s) ((s) ? strlen(s) : 0)
......@@ -181,10 +182,8 @@ XSetIconSizes (
{
register int i;
xPropIconSize *pp, *prop;
#define size_of_the_real_thing sizeof /* avoid grepping screwups */
unsigned nbytes = count * size_of_the_real_thing(xPropIconSize);
#undef size_of_the_real_thing
if ((prop = pp = Xmalloc (nbytes))) {
if ((prop = pp = Xmallocarray (count, sizeof(xPropIconSize)))) {
for (i = 0; i < count; i++) {
pp->minWidth = list->min_width;
pp->minHeight = list->min_height;
......
......@@ -34,6 +34,7 @@ from The Open Group.
#include <X11/Xutil.h>
#include "Xatomtype.h"
#include <X11/Xatom.h>
#include "reallocarray.h"
void XSetRGBColormaps (
Display *dpy,
......@@ -55,9 +56,9 @@ void XSetRGBColormaps (
/*
* if doing more than one, allocate scratch space for it
*/
if ((count > 1) && ((data = ((xPropStandardColormap *)
Xmalloc(count*sizeof(xPropStandardColormap))))
!= NULL)) {
if ((count > 1) &&
((data = (Xmallocarray(count,
sizeof(xPropStandardColormap)))) != NULL)) {
alloced_scratch_space = True;
} else {
data = &tmpdata;
......
......@@ -31,7 +31,7 @@ in this Software without prior written authorization from The Open Group.
#include <X11/Xlibint.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include "reallocarray.h"
/*
* XTextPropertyToStringList - set list and count to contain data stored in
......@@ -72,7 +72,7 @@ Status XTextPropertyToStringList (
/*
* allocate list and duplicate
*/
list = Xmalloc (nelements * sizeof (char *));
list = Xmallocarray (nelements, sizeof (char *));
if (!list) return False;
start = Xmalloc ((datalen + 1) * sizeof (char)); /* for <NUL> */
......
......@@ -30,6 +30,8 @@ in this Software without prior written authorization from The Open Group.
#include "Xlibint.h"
#include "Xutil.h"
#include <stdio.h>
#include "reallocarray.h"
/*
* This procedure returns a list of visual information structures
* that match the specified attributes given in the visual information
......@@ -75,7 +77,7 @@ XVisualInfo *XGetVisualInfo(
count = 0;
total = 10;
if (! (vip_base = vip = Xmalloc(sizeof(XVisualInfo) * total))) {
if (! (vip_base = vip = Xmallocarray(total, sizeof(XVisualInfo)))) {
UnlockDisplay(dpy);
return (XVisualInfo *) NULL;
}
......@@ -131,8 +133,8 @@ XVisualInfo *XGetVisualInfo(
{
XVisualInfo *old_vip_base = vip_base;
total += 10;
if (! (vip_base = Xrealloc(vip_base,
sizeof(XVisualInfo) * total))) {
if (! (vip_base = Xreallocarray(vip_base, total,
sizeof(XVisualInfo)))) {
Xfree(old_vip_base);
UnlockDisplay(dpy);
return (XVisualInfo *) NULL;
......
......@@ -33,6 +33,7 @@ from The Open Group.
#include <X11/Xos.h>
#include "Xutil.h"
#include <stdio.h>
#include "reallocarray.h"
#define ERR_RETURN NULL
......@@ -53,7 +54,7 @@ static char *Format_Image(
bytes_per_line = (width+7)/8;
*resultsize = bytes_per_line * height; /* Calculate size of data */
data = Xmalloc( *resultsize ); /* Get space for data */
data = Xmallocarray(bytes_per_line, height); /* Get space for data */
if (!data)
return(ERR_RETURN);
......
......@@ -39,6 +39,7 @@ from The Open Group.
#endif
#include "Xlibint.h"
#include "Xprivate.h"
#include "reallocarray.h"
#include <X11/Xpoll.h>
#include <assert.h>
#include <stdio.h>
......@@ -349,7 +350,7 @@ _XRegisterInternalConnection(
new_conni = Xmalloc(sizeof(struct _XConnectionInfo));
if (!new_conni)
return 0;
new_conni->watch_data = Xmalloc(dpy->watcher_count * sizeof(XPointer));
new_conni->watch_data = Xmallocarray(dpy->watcher_count, sizeof(XPointer));
if (!new_conni->watch_data) {
Xfree(new_conni);
return 0;
......@@ -435,7 +436,7 @@ XInternalConnectionNumbers(
count = 0;
for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next)
count++;
fd_list = Xmalloc (count * sizeof(int));
fd_list = Xmallocarray (count, sizeof(int));
if (!fd_list) {
UnlockDisplay(dpy);
return 0;
......@@ -508,8 +509,8 @@ XAddConnectionWatch(
/* allocate new watch data */
for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next) {
wd_array = Xrealloc(info_list->watch_data,
(dpy->watcher_count + 1) * sizeof(XPointer));
wd_array = Xreallocarray(info_list->watch_data,
dpy->watcher_count + 1, sizeof(XPointer));
if (!wd_array) {
UnlockDisplay(dpy);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment