xalloc+memset(0) -> xcalloc

This commit is contained in:
Adam Jackson 2008-10-06 15:36:51 -04:00
parent 0b7b89fbac
commit 8a5b89e8e1
43 changed files with 67 additions and 178 deletions

View File

@ -133,9 +133,7 @@ ProcXResQueryClientResources (ClientPtr client)
return BadValue; return BadValue;
} }
counts = xalloc((lastResourceType + 1) * sizeof(int)); counts = xcalloc(lastResourceType + 1, sizeof(int));
memset(counts, 0, (lastResourceType + 1) * sizeof(int));
FindAllClientResources(clients[clientID], ResFindAllRes, counts); FindAllClientResources(clients[clientID], ResFindAllRes, counts);

View File

@ -147,13 +147,10 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
if (devid >= MAX_DEVICES) if (devid >= MAX_DEVICES)
return (DeviceIntPtr)NULL; return (DeviceIntPtr)NULL;
dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), 1); dev = xcalloc(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), 1);
if (!dev) if (!dev)
return (DeviceIntPtr)NULL; return (DeviceIntPtr)NULL;
dev->name = (char *)NULL;
dev->type = 0;
dev->id = devid; dev->id = devid;
dev->public.on = FALSE;
dev->public.processInputProc = (ProcessInputProc)NoopDDA; dev->public.processInputProc = (ProcessInputProc)NoopDDA;
dev->public.realInputProc = (ProcessInputProc)NoopDDA; dev->public.realInputProc = (ProcessInputProc)NoopDDA;
dev->public.enqueueInputProc = EnqueueEvent; dev->public.enqueueInputProc = EnqueueEvent;
@ -161,51 +158,12 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
dev->startup = autoStart; dev->startup = autoStart;
/* device grab defaults */ /* device grab defaults */
dev->deviceGrab.sync.frozen = FALSE;
dev->deviceGrab.sync.other = NullGrab;
dev->deviceGrab.sync.state = NOT_GRABBED;
dev->deviceGrab.sync.event = (xEvent *) NULL;
dev->deviceGrab.sync.evcount = 0;
dev->deviceGrab.grab = NullGrab;
dev->deviceGrab.grabTime = currentTime; dev->deviceGrab.grabTime = currentTime;
dev->deviceGrab.fromPassiveGrab = FALSE;
dev->deviceGrab.implicitGrab = FALSE;
dev->key = (KeyClassPtr)NULL;
dev->valuator = (ValuatorClassPtr)NULL;
dev->button = (ButtonClassPtr)NULL;
dev->focus = (FocusClassPtr)NULL;
dev->proximity = (ProximityClassPtr)NULL;
dev->absolute = (AbsoluteClassPtr)NULL;
dev->kbdfeed = (KbdFeedbackPtr)NULL;
dev->ptrfeed = (PtrFeedbackPtr)NULL;
dev->intfeed = (IntegerFeedbackPtr)NULL;
dev->stringfeed = (StringFeedbackPtr)NULL;
dev->bell = (BellFeedbackPtr)NULL;
dev->leds = (LedFeedbackPtr)NULL;
#ifdef XKB
dev->xkb_interest = NULL;
#endif
dev->config_info = NULL;
dev->devPrivates = NULL;
dev->unwrapProc = NULL;
dev->coreEvents = TRUE; dev->coreEvents = TRUE;
dev->inited = FALSE;
dev->enabled = FALSE;
/* sprite defaults */ /* sprite defaults */
dev->spriteInfo = (SpriteInfoPtr)&dev[1]; dev->spriteInfo = (SpriteInfoPtr)&dev[1];
dev->spriteInfo->sprite = NULL;
dev->spriteInfo->spriteOwner = FALSE;
/* last valuators */
memset(dev->last.valuators, 0, sizeof(dev->last.valuators));
memset(dev->last.remainder, 0, sizeof(dev->last.remainder));
dev->last.numValuators = 0;
/* device properties */
dev->properties.properties = NULL;
dev->properties.handlers = NULL;
/* security creation/labeling check /* security creation/labeling check
*/ */

View File

@ -164,11 +164,10 @@ static __GLXcontext *__glXdirectContextCreate(__GLXscreen *screen,
{ {
__GLXcontext *context; __GLXcontext *context;
context = xalloc (sizeof (__GLXcontext)); context = xcalloc (1, sizeof (__GLXcontext));
if (context == NULL) if (context == NULL)
return NULL; return NULL;
memset(context, 0, sizeof *context);
context->destroy = __glXdirectContextDestroy; context->destroy = __glXdirectContextDestroy;
return context; return context;

View File

@ -613,11 +613,10 @@ __glXDRIscreenCreateContext(__GLXscreen *baseScreen,
if (baseShareContext && baseShareContext->isDirect) if (baseShareContext && baseShareContext->isDirect)
return NULL; return NULL;
context = xalloc(sizeof *context); context = xcalloc(1, sizeof *context);
if (context == NULL) if (context == NULL)
return NULL; return NULL;
memset(context, 0, sizeof *context);
context->base.destroy = __glXDRIcontextDestroy; context->base.destroy = __glXDRIcontextDestroy;
context->base.makeCurrent = __glXDRIcontextMakeCurrent; context->base.makeCurrent = __glXDRIcontextMakeCurrent;
context->base.loseCurrent = __glXDRIcontextLoseCurrent; context->base.loseCurrent = __glXDRIcontextLoseCurrent;
@ -672,12 +671,10 @@ __glXDRIscreenCreateDrawable(__GLXscreen *screen,
GLboolean retval; GLboolean retval;
drm_drawable_t hwDrawable; drm_drawable_t hwDrawable;
private = xalloc(sizeof *private); private = xcalloc(1, sizeof *private);
if (private == NULL) if (private == NULL)
return NULL; return NULL;
memset(private, 0, sizeof *private);
if (!__glXDrawableInit(&private->base, screen, if (!__glXDrawableInit(&private->base, screen,
pDraw, type, drawId, glxConfig)) { pDraw, type, drawId, glxConfig)) {
xfree(private); xfree(private);
@ -950,10 +947,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
return NULL; return NULL;
} }
screen = xalloc(sizeof *screen); screen = xcalloc(1, sizeof *screen);
if (screen == NULL) if (screen == NULL)
return NULL; return NULL;
memset(screen, 0, sizeof *screen);
screen->base.destroy = __glXDRIscreenDestroy; screen->base.destroy = __glXDRIscreenDestroy;
screen->base.createContext = __glXDRIscreenCreateContext; screen->base.createContext = __glXDRIscreenCreateContext;

View File

@ -279,11 +279,10 @@ __glXDRIscreenCreateContext(__GLXscreen *baseScreen,
else else
driShare = NULL; driShare = NULL;
context = xalloc(sizeof *context); context = xcalloc(1, sizeof *context);
if (context == NULL) if (context == NULL)
return NULL; return NULL;
memset(context, 0, sizeof *context);
context->base.destroy = __glXDRIcontextDestroy; context->base.destroy = __glXDRIcontextDestroy;
context->base.makeCurrent = __glXDRIcontextMakeCurrent; context->base.makeCurrent = __glXDRIcontextMakeCurrent;
context->base.loseCurrent = __glXDRIcontextLoseCurrent; context->base.loseCurrent = __glXDRIcontextLoseCurrent;
@ -310,12 +309,10 @@ __glXDRIscreenCreateDrawable(__GLXscreen *screen,
__GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig; __GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
__GLXDRIdrawable *private; __GLXDRIdrawable *private;
private = xalloc(sizeof *private); private = xcalloc(1, sizeof *private);
if (private == NULL) if (private == NULL)
return NULL; return NULL;
memset(private, 0, sizeof *private);
private->screen = driScreen; private->screen = driScreen;
if (!__glXDrawableInit(&private->base, screen, if (!__glXDrawableInit(&private->base, screen,
pDraw, type, drawId, glxConfig)) { pDraw, type, drawId, glxConfig)) {
@ -464,10 +461,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
const __DRIconfig **driConfigs; const __DRIconfig **driConfigs;
int i; int i;
screen = xalloc(sizeof *screen); screen = xcalloc(1, sizeof *screen);
if (screen == NULL) if (screen == NULL)
return NULL; return NULL;
memset(screen, 0, sizeof *screen);
if (!xf86LoaderCheckSymbol("DRI2Connect") || if (!xf86LoaderCheckSymbol("DRI2Connect") ||
!DRI2Connect(pScreen, &screen->fd, &driverName)) { !DRI2Connect(pScreen, &screen->fd, &driverName)) {

View File

@ -265,11 +265,10 @@ __glXDRIscreenCreateContext(__GLXscreen *baseScreen,
else else
driShare = NULL; driShare = NULL;
context = xalloc(sizeof *context); context = xcalloc(1, sizeof *context);
if (context == NULL) if (context == NULL)
return NULL; return NULL;
memset(context, 0, sizeof *context);
context->base.destroy = __glXDRIcontextDestroy; context->base.destroy = __glXDRIcontextDestroy;
context->base.makeCurrent = __glXDRIcontextMakeCurrent; context->base.makeCurrent = __glXDRIcontextMakeCurrent;
context->base.loseCurrent = __glXDRIcontextLoseCurrent; context->base.loseCurrent = __glXDRIcontextLoseCurrent;
@ -305,12 +304,10 @@ __glXDRIscreenCreateDrawable(__GLXscreen *screen,
ScreenPtr pScreen = driScreen->base.pScreen; ScreenPtr pScreen = driScreen->base.pScreen;
private = xalloc(sizeof *private); private = xcalloc(1, sizeof *private);
if (private == NULL) if (private == NULL)
return NULL; return NULL;
memset(private, 0, sizeof *private);
private->screen = driScreen; private->screen = driScreen;
if (!__glXDrawableInit(&private->base, screen, if (!__glXDrawableInit(&private->base, screen,
pDraw, type, drawId, glxConfig)) { pDraw, type, drawId, glxConfig)) {
@ -442,10 +439,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
const __DRIconfig **driConfigs; const __DRIconfig **driConfigs;
int i; int i;
screen = xalloc(sizeof *screen); screen = xcalloc(1, sizeof *screen);
if (screen == NULL) if (screen == NULL)
return NULL; return NULL;
memset(screen, 0, sizeof *screen);
screen->base.destroy = __glXDRIscreenDestroy; screen->base.destroy = __glXDRIscreenDestroy;
screen->base.createContext = __glXDRIscreenCreateContext; screen->base.createContext = __glXDRIscreenCreateContext;

View File

@ -65,12 +65,11 @@ void dmxConfigLog(const char *format, ...)
void *dmxConfigAlloc(unsigned long bytes) void *dmxConfigAlloc(unsigned long bytes)
{ {
void *area = malloc(bytes); void *area = calloc(1, bytes);
if (!area) { if (!area) {
dmxConfigLog("dmxConfigAlloc: out of memory\n"); dmxConfigLog("dmxConfigAlloc: out of memory\n");
return NULL; return NULL;
} }
memset(area, 0, bytes);
return area; return area;
} }
@ -249,8 +248,6 @@ DMXConfigDisplayPtr dmxConfigCreateDisplay(DMXConfigTokenPtr pStart,
{ {
DMXConfigDisplayPtr pDisplay = dmxConfigAlloc(sizeof(*pDisplay)); DMXConfigDisplayPtr pDisplay = dmxConfigAlloc(sizeof(*pDisplay));
memset(pDisplay, 0, sizeof(*pDisplay));
pDisplay->start = pStart; pDisplay->start = pStart;
pDisplay->dname = pName; pDisplay->dname = pName;
pDisplay->dim = pDim; pDisplay->dim = pDim;

View File

@ -341,16 +341,14 @@ do { \
#define _MAXSCREENSALLOCF(o,size,fatal) \ #define _MAXSCREENSALLOCF(o,size,fatal) \
do { \ do { \
if (!o) { \ if (!o) { \
o = xalloc((size) * sizeof(*(o))); \ o = xcalloc((size), sizeof(*(o))); \
if (o) memset(o, 0, (size) * sizeof(*(o))); \
if (!o && fatal) FatalError(MAXSCREEN_FAILED_TXT #o); \ if (!o && fatal) FatalError(MAXSCREEN_FAILED_TXT #o); \
} \ } \
} while (0) } while (0)
#define _MAXSCREENSALLOCR(o,size,retval) \ #define _MAXSCREENSALLOCR(o,size,retval) \
do { \ do { \
if (!o) { \ if (!o) { \
o = xalloc((size) * sizeof(*(o))); \ o = xcalloc((size), sizeof(*(o))); \
if (o) memset(o, 0, (size) * sizeof(*(o))); \
if (!o) return retval; \ if (!o) return retval; \
} \ } \
} while (0) } while (0)

View File

@ -1121,11 +1121,10 @@ static void dmxBERestoreRenderGlyph(pointer value, XID id, pointer n)
} }
/* Now allocate the memory we need */ /* Now allocate the memory we need */
images = xalloc(len_images*sizeof(char)); images = xcalloc(len_images, sizeof(char));
gids = xalloc(glyphSet->hash.tableEntries*sizeof(Glyph)); gids = xalloc(glyphSet->hash.tableEntries*sizeof(Glyph));
glyphs = xalloc(glyphSet->hash.tableEntries*sizeof(XGlyphInfo)); glyphs = xalloc(glyphSet->hash.tableEntries*sizeof(XGlyphInfo));
memset(images, 0, len_images * sizeof(char));
pos = images; pos = images;
ctr = 0; ctr = 0;

View File

@ -115,8 +115,7 @@ void dmxStatActivate(const char *interval, const char *displays)
/** Allocate a \a DMXStatInfo structure. */ /** Allocate a \a DMXStatInfo structure. */
DMXStatInfo *dmxStatAlloc(void) DMXStatInfo *dmxStatAlloc(void)
{ {
DMXStatInfo *pt = malloc(sizeof(*pt)); DMXStatInfo *pt = calloc(1, sizeof(*pt));
memset(pt, 0, sizeof(*pt));
return pt; return pt;
} }

View File

@ -146,11 +146,10 @@ static int CreateContext(__GLXclientState *cl,
/* /*
** Allocate memory for the new context ** Allocate memory for the new context
*/ */
glxc = (__GLXcontext *) __glXMalloc(sizeof(__GLXcontext)); glxc = __glXCalloc(1, sizeof(__GLXcontext));
if (!glxc) { if (!glxc) {
return BadAlloc; return BadAlloc;
} }
memset(glxc, 0, sizeof(__GLXcontext));
pScreen = screenInfo.screens[screen]; pScreen = screenInfo.screens[screen];
pGlxScreen = &__glXActiveScreens[screen]; pGlxScreen = &__glXActiveScreens[screen];

View File

@ -419,19 +419,17 @@ static int __glXDispatch(ClientPtr client)
opcode = stuff->glxCode; opcode = stuff->glxCode;
cl = __glXClients[client->index]; cl = __glXClients[client->index];
if (!cl) { if (!cl) {
cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); cl = __glXCalloc(1, sizeof(__GLXclientState));
__glXClients[client->index] = cl; __glXClients[client->index] = cl;
if (!cl) { if (!cl) {
return BadAlloc; return BadAlloc;
} }
memset(cl, 0, sizeof(__GLXclientState));
cl->be_displays = (Display **) __glXMalloc( screenInfo.numScreens * sizeof(Display *) ); cl->be_displays = __glXCalloc(screenInfo.numScreens, sizeof(Display *));
if (!cl->be_displays) { if (!cl->be_displays) {
__glXFree( cl ); __glXFree( cl );
return BadAlloc; return BadAlloc;
} }
memset(cl->be_displays, 0, screenInfo.numScreens * sizeof(Display *));
} }
if (!cl->inUse) { if (!cl->inUse) {
@ -473,20 +471,17 @@ static int __glXSwapDispatch(ClientPtr client)
opcode = stuff->glxCode; opcode = stuff->glxCode;
cl = __glXClients[client->index]; cl = __glXClients[client->index];
if (!cl) { if (!cl) {
cl = (__GLXclientState *) __glXMalloc(sizeof(__GLXclientState)); cl = __glXCalloc(1, sizeof(__GLXclientState));
__glXClients[client->index] = cl; __glXClients[client->index] = cl;
if (!cl) { if (!cl) {
return BadAlloc; return BadAlloc;
} }
memset(cl, 0, sizeof(__GLXclientState));
cl->be_displays = (Display **) __glXMalloc( screenInfo.numScreens * sizeof(Display *) ); cl->be_displays = __glXCalloc(screenInfo.numScreens, sizeof(Display *));
if (!cl->be_displays) { if (!cl->be_displays) {
__glXFree( cl ); __glXFree( cl );
return BadAlloc; return BadAlloc;
} }
memset(cl->be_displays, 0, screenInfo.numScreens * sizeof(Display *));
} }
if (!cl->inUse) { if (!cl->inUse) {

View File

@ -69,13 +69,11 @@ __glXCalloc(size_t numElements, size_t elementSize)
if ((numElements == 0) || (elementSize == 0)) { if ((numElements == 0) || (elementSize == 0)) {
return NULL; return NULL;
} }
size = numElements * elementSize; addr = xcalloc(numElements, elementSize);
addr = (void *) xalloc(size);
if (addr == NULL) { if (addr == NULL) {
/* XXX: handle out of memory error */ /* XXX: handle out of memory error */
return NULL; return NULL;
} }
memset(addr, 0, size);
return addr; return addr;
} }

View File

@ -104,8 +104,7 @@ typedef struct _myPrivate {
pointer dmxBackendCreatePrivate(DeviceIntPtr pDevice) pointer dmxBackendCreatePrivate(DeviceIntPtr pDevice)
{ {
GETDMXLOCALFROMPDEVICE; GETDMXLOCALFROMPDEVICE;
myPrivate *priv = xalloc(sizeof(*priv)); myPrivate *priv = xcalloc(1, sizeof(*priv));
memset(priv, 0, sizeof(*priv));
priv->dmxLocal = dmxLocal; priv->dmxLocal = dmxLocal;
return priv; return priv;
} }

View File

@ -140,8 +140,7 @@ static int unscaley(myPrivate *priv, int y)
pointer dmxConsoleCreatePrivate(DeviceIntPtr pDevice) pointer dmxConsoleCreatePrivate(DeviceIntPtr pDevice)
{ {
GETDMXLOCALFROMPDEVICE; GETDMXLOCALFROMPDEVICE;
myPrivate *priv = xalloc(sizeof(*priv)); myPrivate *priv = xcalloc(1, sizeof(*priv));
memset(priv, 0, sizeof(*priv));
priv->dmxLocal = dmxLocal; priv->dmxLocal = dmxLocal;
return priv; return priv;
} }

View File

@ -113,8 +113,7 @@ void dmxPointerPutMotionEvent(DeviceIntPtr pDevice,
* DMX_MOTION_SIZE); * DMX_MOTION_SIZE);
dmxLocal->head = 0; dmxLocal->head = 0;
dmxLocal->tail = 0; dmxLocal->tail = 0;
dmxLocal->valuators = xalloc(sizeof(*dmxLocal->valuators) * numAxes); dmxLocal->valuators = xcalloc(sizeof(*dmxLocal->valuators), numAxes);
memset(dmxLocal->valuators, 0, sizeof(*dmxLocal->valuators) * numAxes);
} else { } else {
if (++dmxLocal->tail >= DMX_MOTION_SIZE) dmxLocal->tail = 0; if (++dmxLocal->tail >= DMX_MOTION_SIZE) dmxLocal->tail = 0;
if (dmxLocal->head == dmxLocal->tail) if (dmxLocal->head == dmxLocal->tail)

View File

@ -358,8 +358,7 @@ static unsigned char at2lnx[NUM_KEYCODES] =
/** Create a private structure for use within this file. */ /** Create a private structure for use within this file. */
pointer kbdLinuxCreatePrivate(DeviceIntPtr pKeyboard) pointer kbdLinuxCreatePrivate(DeviceIntPtr pKeyboard)
{ {
myPrivate *priv = xalloc(sizeof(*priv)); myPrivate *priv = xcalloc(1, sizeof(*priv));
memset(priv, 0, sizeof(*priv));
priv->fd = -1; priv->fd = -1;
priv->pKeyboard = pKeyboard; priv->pKeyboard = pKeyboard;
return priv; return priv;

View File

@ -292,8 +292,7 @@ void msLinuxVTPostSwitch(pointer p)
/** Create a private structure for use within this file. */ /** Create a private structure for use within this file. */
pointer msLinuxCreatePrivate(DeviceIntPtr pMouse) pointer msLinuxCreatePrivate(DeviceIntPtr pMouse)
{ {
myPrivate *priv = xalloc(sizeof(*priv)); myPrivate *priv = xcalloc(1, sizeof(*priv));
memset(priv, 0, sizeof(*priv));
priv->fd = -1; priv->fd = -1;
priv->pMouse = pMouse; priv->pMouse = pMouse;
return priv; return priv;

View File

@ -260,8 +260,7 @@ void ps2LinuxVTPostSwitch(pointer p)
/** Create a private structure for use within this file. */ /** Create a private structure for use within this file. */
pointer ps2LinuxCreatePrivate(DeviceIntPtr pMouse) pointer ps2LinuxCreatePrivate(DeviceIntPtr pMouse)
{ {
myPrivate *priv = xalloc(sizeof(*priv)); myPrivate *priv = xcalloc(1, sizeof(*priv));
memset(priv, 0, sizeof(*priv));
priv->fd = -1; priv->fd = -1;
priv->pMouse = pMouse; priv->pMouse = pMouse;
return priv; return priv;

View File

@ -368,8 +368,7 @@ void usbOff(DevicePtr pDev)
/** Create a private structure for use within this file. */ /** Create a private structure for use within this file. */
pointer usbCreatePrivate(DeviceIntPtr pDevice) pointer usbCreatePrivate(DeviceIntPtr pDevice)
{ {
myPrivate *priv = xalloc(sizeof(*priv)); myPrivate *priv = xcalloc(1, sizeof(*priv));
memset(priv, 0, sizeof(*priv));
priv->fd = -1; priv->fd = -1;
priv->pDevice = pDevice; priv->pDevice = pDevice;
return priv; return priv;

View File

@ -185,12 +185,11 @@ ephyrScreenInit (KdScreenInfo *screen)
{ {
EphyrScrPriv *scrpriv; EphyrScrPriv *scrpriv;
scrpriv = xalloc (sizeof (EphyrScrPriv)); scrpriv = xcalloc (1, sizeof (EphyrScrPriv));
if (!scrpriv) if (!scrpriv)
return FALSE; return FALSE;
memset (scrpriv, 0, sizeof (EphyrScrPriv));
screen->driver = scrpriv; screen->driver = scrpriv;
if (!ephyrScreenInitialize (screen, scrpriv)) if (!ephyrScreenInitialize (screen, scrpriv))

View File

@ -121,10 +121,9 @@ fakeScreenInit (KdScreenInfo *screen)
{ {
FakeScrPriv *scrpriv; FakeScrPriv *scrpriv;
scrpriv = xalloc (sizeof (FakeScrPriv)); scrpriv = xcalloc (1, sizeof (FakeScrPriv));
if (!scrpriv) if (!scrpriv)
return FALSE; return FALSE;
memset (scrpriv, '\0', sizeof (FakeScrPriv));
screen->driver = scrpriv; screen->driver = scrpriv;
if (!fakeScreenInitialize (screen, scrpriv)) if (!fakeScreenInitialize (screen, scrpriv))
{ {

View File

@ -297,10 +297,9 @@ fbdevScreenInit (KdScreenInfo *screen)
{ {
FbdevScrPriv *scrpriv; FbdevScrPriv *scrpriv;
scrpriv = xalloc (sizeof (FbdevScrPriv)); scrpriv = xcalloc (1, sizeof (FbdevScrPriv));
if (!scrpriv) if (!scrpriv)
return FALSE; return FALSE;
memset (scrpriv, '\0', sizeof (FbdevScrPriv));
screen->driver = scrpriv; screen->driver = scrpriv;
if (!fbdevScreenInitialize (screen, scrpriv)) if (!fbdevScreenInitialize (screen, scrpriv))
{ {

View File

@ -251,13 +251,12 @@ EvdevPtrEnable (KdPointerInfo *pi)
close (fd); close (fd);
return BadMatch; return BadMatch;
} }
ke = xalloc (sizeof (Kevdev)); ke = xcalloc (1, sizeof (Kevdev));
if (!ke) if (!ke)
{ {
close (fd); close (fd);
return BadAlloc; return BadAlloc;
} }
memset (ke, '\0', sizeof (Kevdev));
if (ISBITSET (ev, EV_KEY)) if (ISBITSET (ev, EV_KEY))
{ {
if (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (ke->keybits)), if (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (ke->keybits)),
@ -440,12 +439,11 @@ EvdevKbdEnable (KdKeyboardInfo *ki)
return BadMatch; return BadMatch;
} }
ke = xalloc (sizeof (Kevdev)); ke = xcalloc (1, sizeof (Kevdev));
if (!ke) { if (!ke) {
close (fd); close (fd);
return BadAlloc; return BadAlloc;
} }
memset (ke, '\0', sizeof (Kevdev));
if (!KdRegisterFd (fd, EvdevKbdRead, ki)) { if (!KdRegisterFd (fd, EvdevKbdRead, ki)) {
xfree (ke); xfree (ke);

View File

@ -739,10 +739,9 @@ KdAllocatePrivates (ScreenPtr pScreen)
if (kdGeneration != serverGeneration) if (kdGeneration != serverGeneration)
kdGeneration = serverGeneration; kdGeneration = serverGeneration;
pScreenPriv = (KdPrivScreenPtr) xalloc(sizeof (*pScreenPriv)); pScreenPriv = xcalloc(1, sizeof (*pScreenPriv));
if (!pScreenPriv) if (!pScreenPriv)
return FALSE; return FALSE;
memset (pScreenPriv, '\0', sizeof (KdPrivScreenRec));
KdSetScreenPriv (pScreen, pScreenPriv); KdSetScreenPriv (pScreen, pScreenPriv);
return TRUE; return TRUE;
} }

View File

@ -175,10 +175,8 @@ vesaGetModes (Vm86InfoPtr vi, int *ret_nmode)
if (nmode <= 0) if (nmode <= 0)
return 0; return 0;
modes = xalloc (nmode * sizeof (VesaModeRec)); modes = xcalloc (nmode, sizeof (VesaModeRec));
memset (modes, '\0', nmode * sizeof (VesaModeRec));
if (nmodeVga) if (nmodeVga)
{ {
code = VgaGetModes (vi, modes, nmodeVga); code = VgaGetModes (vi, modes, nmodeVga);

View File

@ -295,11 +295,10 @@ autoConfigDevice(GDevPtr preconf_device)
if (preconf_device) { if (preconf_device) {
ptr = preconf_device; ptr = preconf_device;
} else { } else {
ptr = (GDevPtr)xalloc(sizeof(GDevRec)); ptr = xcalloc(1, sizeof(GDevRec));
if (!ptr) { if (!ptr) {
return NULL; return NULL;
} }
memset((GDevPtr)ptr, 0, sizeof(GDevRec));
ptr->chipID = -1; ptr->chipID = -1;
ptr->chipRev = -1; ptr->chipRev = -1;
ptr->irq = -1; ptr->irq = -1;

View File

@ -287,8 +287,7 @@ configureInputSection (void)
#endif #endif
} }
mouse = xf86confmalloc(sizeof(XF86ConfInputRec)); mouse = xf86confcalloc(1, sizeof(XF86ConfInputRec));
memset((XF86ConfInputPtr)mouse,0,sizeof(XF86ConfInputRec));
mouse->inp_identifier = "Mouse0"; mouse->inp_identifier = "Mouse0";
mouse->inp_driver = "mouse"; mouse->inp_driver = "mouse";
mouse->inp_option_lst = mouse->inp_option_lst =
@ -324,8 +323,7 @@ configureScreenSection (int screennum)
{ {
XF86ConfDisplayPtr display; XF86ConfDisplayPtr display;
display = xf86confmalloc(sizeof(XF86ConfDisplayRec)); display = xf86confcalloc(1, sizeof(XF86ConfDisplayRec));
memset((XF86ConfDisplayPtr)display,0,sizeof(XF86ConfDisplayRec));
display->disp_depth = depths[i]; display->disp_depth = depths[i];
display->disp_black.red = display->disp_white.red = -1; display->disp_black.red = display->disp_white.red = -1;
display->disp_black.green = display->disp_white.green = -1; display->disp_black.green = display->disp_white.green = -1;
@ -526,8 +524,7 @@ configureModuleSection (void)
for (el = elist; *el; el++) { for (el = elist; *el; el++) {
XF86LoadPtr module; XF86LoadPtr module;
module = xf86confmalloc(sizeof(XF86LoadRec)); module = xf86confcalloc(1, sizeof(XF86LoadRec));
memset((XF86LoadPtr)module,0,sizeof(XF86LoadRec));
module->load_name = *el; module->load_name = *el;
ptr->mod_load_lst = (XF86LoadPtr)xf86addListItem( ptr->mod_load_lst = (XF86LoadPtr)xf86addListItem(
(glp)ptr->mod_load_lst, (glp)module); (glp)ptr->mod_load_lst, (glp)module);
@ -541,8 +538,7 @@ configureModuleSection (void)
for (el = elist; *el; el++) { for (el = elist; *el; el++) {
XF86LoadPtr module; XF86LoadPtr module;
module = xf86confmalloc(sizeof(XF86LoadRec)); module = xf86confcalloc(sizeof(XF86LoadRec));
memset((XF86LoadPtr)module,0,sizeof(XF86LoadRec));
module->load_name = *el; module->load_name = *el;
/* Add only those font backends which are referenced by fontpath */ /* Add only those font backends which are referenced by fontpath */
@ -716,11 +712,7 @@ DoConfigure()
xf86FindPrimaryDevice(); xf86FindPrimaryDevice();
/* Create XF86Config file structure */ /* Create XF86Config file structure */
xf86config = malloc(sizeof(XF86ConfigRec)); xf86config = calloc(1, sizeof(XF86ConfigRec));
memset ((XF86ConfigPtr)xf86config, 0, sizeof(XF86ConfigRec));
xf86config->conf_device_lst = NULL;
xf86config->conf_screen_lst = NULL;
xf86config->conf_monitor_lst = NULL;
/* Call all of the probe functions, reporting the results. */ /* Call all of the probe functions, reporting the results. */
for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) { for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) {

View File

@ -964,9 +964,8 @@ xf86XVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
} }
if(!winPriv) { if(!winPriv) {
winPriv = xalloc(sizeof(XF86XVWindowRec)); winPriv = xcalloc(1, sizeof(XF86XVWindowRec));
if(!winPriv) return BadAlloc; if(!winPriv) return BadAlloc;
memset(winPriv, 0, sizeof(XF86XVWindowRec));
winPriv->PortRec = portPriv; winPriv->PortRec = portPriv;
winPriv->next = PrivRoot; winPriv->next = PrivRoot;
dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, winPriv); dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, winPriv);
@ -1175,7 +1174,7 @@ xf86XVCloseScreen(int i, ScreenPtr pScreen)
int c; int c;
/* Clear offscreen images */ /* Clear offscreen images */
(void)memset(&OffscreenImages[pScreen->myNum], 0, sizeof(OffscreenImages[0])); memset(&OffscreenImages[pScreen->myNum], 0, sizeof(OffscreenImages[0]));
if(!ScreenPriv) return TRUE; if(!ScreenPriv) return TRUE;

View File

@ -176,7 +176,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
* have executable code there. Note that xf86ReadBIOS() can only read in * have executable code there. Note that xf86ReadBIOS() can only read in
* 64kB at a time. * 64kB at a time.
*/ */
(void)memset((char *)base + V_BIOS, 0, SYS_BIOS - V_BIOS); memset((char *)base + V_BIOS, 0, SYS_BIOS - V_BIOS);
#if 0 #if 0
for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE) for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE)
if (xf86ReadBIOS(cs, 0, (unsigned char *)base + cs, V_BIOS_SIZE) < if (xf86ReadBIOS(cs, 0, (unsigned char *)base + cs, V_BIOS_SIZE) <
@ -223,7 +223,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
case BUS_ISA: case BUS_ISA:
vbiosMem = (unsigned char *)sysMem + bios_location; vbiosMem = (unsigned char *)sysMem + bios_location;
#if 0 #if 0
(void)memset(vbiosMem, 0, V_BIOS_SIZE); memset(vbiosMem, 0, V_BIOS_SIZE);
if (xf86ReadBIOS(bios_location, 0, vbiosMem, V_BIOS_SIZE) if (xf86ReadBIOS(bios_location, 0, vbiosMem, V_BIOS_SIZE)
< V_BIOS_SIZE) < V_BIOS_SIZE)
xf86DrvMsg(screen, X_WARNING, xf86DrvMsg(screen, X_WARNING,
@ -255,7 +255,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
* 128KiB. * 128KiB.
*/ */
vbiosMem = (char *)base + V_BIOS; vbiosMem = (char *)base + V_BIOS;
(void)memset(vbiosMem, 0, 2 * V_BIOS_SIZE); memset(vbiosMem, 0, 2 * V_BIOS_SIZE);
if (read_legacy_video_BIOS(pInt->dev, vbiosMem) < V_BIOS_SIZE) { if (read_legacy_video_BIOS(pInt->dev, vbiosMem) < V_BIOS_SIZE) {
xf86DrvMsg(screen, X_WARNING, xf86DrvMsg(screen, X_WARNING,
"Unable to retrieve all of segment 0x0C0000.\n"); "Unable to retrieve all of segment 0x0C0000.\n");

View File

@ -80,8 +80,7 @@ hid_start_parse(report_desc_t d, int kindset)
_DIAGASSERT(d != NULL); _DIAGASSERT(d != NULL);
s = malloc(sizeof *s); s = calloc(1, sizeof *s);
memset(s, 0, sizeof *s);
s->start = s->p = d->data; s->start = s->p = d->data;
s->end = d->data + d->size; s->end = d->data + d->size;
s->kindset = kindset; s->kindset = kindset;

View File

@ -321,7 +321,7 @@ sparcPromAssignNodes(void)
FILE *f; FILE *f;
sbusDevicePtr devicePtrs[32]; sbusDevicePtr devicePtrs[32];
(void)memset(devicePtrs, 0, sizeof(devicePtrs)); memset(devicePtrs, 0, sizeof(devicePtrs));
for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) { for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) {
if (psdp->fbNum != n) if (psdp->fbNum != n)
holes = 1; holes = 1;

View File

@ -106,7 +106,7 @@ linuxPciInit(void)
struct stat st; struct stat st;
#ifndef INCLUDE_XF86_NO_DOMAIN #ifndef INCLUDE_XF86_NO_DOMAIN
(void) memset(DomainMmappedIO, 0, sizeof(DomainMmappedIO)); memset(DomainMmappedIO, 0, sizeof(DomainMmappedIO));
#endif #endif
if (-1 == stat("/proc/bus/pci", &st)) { if (-1 == stat("/proc/bus/pci", &st)) {

View File

@ -245,7 +245,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
* 64K bytes at a time. * 64K bytes at a time.
*/ */
if (!videoBiosMapped) { if (!videoBiosMapped) {
(void)memset((pointer)V_BIOS, 0, SYS_BIOS - V_BIOS); memset((pointer)V_BIOS, 0, SYS_BIOS - V_BIOS);
#ifdef DEBUG #ifdef DEBUG
ErrorF("Reading BIOS\n"); ErrorF("Reading BIOS\n");
#endif #endif

View File

@ -244,8 +244,8 @@ xf86CloseConsole(void)
"xf86CloseConsole(): unable to mmap framebuffer" "xf86CloseConsole(): unable to mmap framebuffer"
" (%s)\n", strerror(errno)); " (%s)\n", strerror(errno));
} else { } else {
(void)memset(fbdata, 0, fbattr.fbtype.fb_size); memset(fbdata, 0, fbattr.fbtype.fb_size);
(void)munmap(fbdata, fbattr.fbtype.fb_size); munmap(fbdata, fbattr.fbtype.fb_size);
} }
} }

View File

@ -100,12 +100,10 @@ LexRec, *LexPtr;
#define TestFree(a) if (a) { xf86conffree (a); a = NULL; } #define TestFree(a) if (a) { xf86conffree (a); a = NULL; }
#define parsePrologue(typeptr,typerec) typeptr ptr; \ #define parsePrologue(typeptr,typerec) typeptr ptr; \
if( (ptr=(typeptr)xf86confcalloc(1,sizeof(typerec))) == NULL ) { return NULL; } \ if( (ptr=(typeptr)xf86confcalloc(1,sizeof(typerec))) == NULL ) { return NULL; }
memset(ptr,0,sizeof(typerec));
#define parsePrologueVoid(typeptr,typerec) int token; typeptr ptr; \ #define parsePrologueVoid(typeptr,typerec) int token; typeptr ptr; \
if( (ptr=(typeptr)xf86confcalloc(1,sizeof(typerec))) == NULL ) { return; } \ if( (ptr=(typeptr)xf86confcalloc(1,sizeof(typerec))) == NULL ) { return; }
memset(ptr,0,sizeof(typerec));
#define HANDLE_RETURN(f,func)\ #define HANDLE_RETURN(f,func)\
if ((ptr->f=func) == NULL)\ if ((ptr->f=func) == NULL)\

View File

@ -100,7 +100,6 @@ xf86readConfigFile (void)
{ {
return NULL; return NULL;
} }
memset (ptr, 0, sizeof (XF86ConfigRec));
while ((token = xf86getToken (TopLevelTab)) != EOF_TOKEN) while ((token = xf86getToken (TopLevelTab)) != EOF_TOKEN)
{ {

View File

@ -255,7 +255,7 @@ RealizeCursorInterleave0(xf86CursorInfoPtr infoPtr, CursorPtr pCurs)
DstM = (SCANLINE*)mem; DstM = (SCANLINE*)mem;
if (!(infoPtr->Flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK)) if (!(infoPtr->Flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK))
DstM += words; DstM += words;
(void)memset(DstM, -1, words * sizeof(SCANLINE)); memset(DstM, -1, words * sizeof(SCANLINE));
} }
return mem; return mem;
} }

View File

@ -171,11 +171,9 @@ __glXAquaScreenCreateContext(__GLXscreen *screen,
GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n"); GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n");
context = malloc (sizeof (__GLXAquaContext)); context = calloc (1, sizeof (__GLXAquaContext));
if (context == NULL) return NULL; if (context == NULL) return NULL;
memset(context, 0, sizeof *context);
context->base.pGlxScreen = screen; context->base.pGlxScreen = screen;
context->base.config = config; context->base.config = config;
@ -1099,8 +1097,7 @@ static void init_screen_visuals(__GLXAquaScreen *screen) {
* FIXME: malloc / free. If nothing else, convert 'used' to * FIXME: malloc / free. If nothing else, convert 'used' to
* FIXME: array of bytes instead of ints! * FIXME: array of bytes instead of ints!
*/ */
used = (int *)malloc(pScreen->numVisuals * sizeof(int)); used = calloc(pScreen->numVisuals, sizeof(int));
memset(used, 0, pScreen->numVisuals * sizeof(int));
i = 0; i = 0;
for ( modes = screen -> base.visuals for ( modes = screen -> base.visuals
@ -1184,11 +1181,9 @@ __glXAquaScreenCreateDrawable(__GLXscreen *screen,
GLAQUA_DEBUG_MSG("glAquaScreenCreateDrawable(%p,%p,%d,%p)\n", context, pDraw, drawId, modes); GLAQUA_DEBUG_MSG("glAquaScreenCreateDrawable(%p,%p,%d,%p)\n", context, pDraw, drawId, modes);
glxPriv = xalloc(sizeof *glxPriv); glxPriv = calloc(1, sizeof *glxPriv);
if (glxPriv == NULL) return NULL; if (glxPriv == NULL) return NULL;
memset(glxPriv, 0, sizeof *glxPriv);
if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, GLX_DRAWABLE_PIXMAP /*?*/, drawId, modes)) { if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, GLX_DRAWABLE_PIXMAP /*?*/, drawId, modes)) {
xfree(glxPriv); xfree(glxPriv);
return NULL; return NULL;

View File

@ -204,8 +204,7 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
/* Allocate memory for the bitmaps */ /* Allocate memory for the bitmaps */
pAnd = malloc (nBytes); pAnd = malloc (nBytes);
memset (pAnd, 0xFF, nBytes); memset (pAnd, 0xFF, nBytes);
pXor = malloc (nBytes); pXor = calloc (1, nBytes);
memset (pXor, 0x00, nBytes);
/* Convert the X11 bitmap to a win32 bitmap /* Convert the X11 bitmap to a win32 bitmap
* The first is for an empty mask */ * The first is for an empty mask */

View File

@ -302,12 +302,10 @@ winXIconToHICON (WindowPtr pWin, int iconSize)
/* Mask is 1-bit deep */ /* Mask is 1-bit deep */
maskStride = ((iconSize * 1 + 31) & (~31)) / 8; maskStride = ((iconSize * 1 + 31) & (~31)) / 8;
image = (unsigned char * ) malloc (stride * iconSize); image = malloc (stride * iconSize);
imageMask = (unsigned char *) malloc (stride * iconSize); imageMask = malloc (stride * iconSize);
mask = (unsigned char *) malloc (maskStride * iconSize);
/* Default to a completely black mask */ /* Default to a completely black mask */
memset (mask, 0, maskStride * iconSize); mask = calloc (maskStride, iconSize);
winScaleXBitmapToWindows (iconSize, effBPP, iconPtr, image); winScaleXBitmapToWindows (iconSize, effBPP, iconPtr, image);
maskPtr = (PixmapPtr) LookupIDByType (hints.icon_mask, RT_PIXMAP); maskPtr = (PixmapPtr) LookupIDByType (hints.icon_mask, RT_PIXMAP);

View File

@ -441,10 +441,9 @@ bail:
Bool Bool
AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet) AllocateGlyphHash (GlyphHashPtr hash, GlyphHashSetPtr hashSet)
{ {
hash->table = (GlyphRefPtr) xalloc (hashSet->size * sizeof (GlyphRefRec)); hash->table = xcalloc (hashSet->size, sizeof (GlyphRefRec));
if (!hash->table) if (!hash->table)
return FALSE; return FALSE;
memset (hash->table, 0, hashSet->size * sizeof (GlyphRefRec));
hash->hashSet = hashSet; hash->hashSet = hashSet;
hash->tableEntries = 0; hash->tableEntries = 0;
return TRUE; return TRUE;

View File

@ -316,10 +316,9 @@ PictureCreateDefaultFormats (ScreenPtr pScreen, int *nformatp)
} }
pFormats = (PictFormatPtr) xalloc (nformats * sizeof (PictFormatRec)); pFormats = xcalloc (nformats, sizeof (PictFormatRec));
if (!pFormats) if (!pFormats)
return 0; return 0;
memset (pFormats, '\0', nformats * sizeof (PictFormatRec));
for (f = 0; f < nformats; f++) for (f = 0; f < nformats; f++)
{ {
pFormats[f].id = FakeClientID (0); pFormats[f].id = FakeClientID (0);