xfree86: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there never can be any hidden bugs or leaks due uninitialized memory. The extra cost of using this compiler intrinsic should be practically impossible to measure - in many cases a good compiler can even deduce if certain areas really don't need to be zero'd (because they're written to right after allocation) and create more efficient machine code. The code pathes in question are pretty cold anyways, so it's probably not worth even thinking about potential extra runtime costs. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
a83f56eb92
commit
d8e6511b1b
|
@ -324,16 +324,14 @@ listPossibleVideoDrivers(XF86MatchedDrivers *md)
|
|||
static Bool
|
||||
copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver)
|
||||
{
|
||||
confScreenPtr nscreen;
|
||||
GDevPtr cptr = NULL;
|
||||
char *identifier;
|
||||
|
||||
nscreen = malloc(sizeof(confScreenRec));
|
||||
confScreenPtr nscreen = calloc(1, sizeof(confScreenRec));
|
||||
if (!nscreen)
|
||||
return FALSE;
|
||||
memcpy(nscreen, oscreen, sizeof(confScreenRec));
|
||||
|
||||
cptr = malloc(sizeof(GDevRec));
|
||||
GDevPtr cptr = calloc(1, sizeof(GDevRec));
|
||||
if (!cptr) {
|
||||
free(nscreen);
|
||||
return FALSE;
|
||||
|
|
|
@ -482,7 +482,7 @@ AddEdge(xf86EdgePtr edge,
|
|||
}
|
||||
|
||||
if (!pEdge) {
|
||||
if (!(pNew = malloc(sizeof(xf86EdgeRec))))
|
||||
if (!(pNew = calloc(1, sizeof(xf86EdgeRec))))
|
||||
break;
|
||||
|
||||
pNew->screen = screen;
|
||||
|
@ -500,7 +500,7 @@ AddEdge(xf86EdgePtr edge,
|
|||
break;
|
||||
}
|
||||
else if (min < pEdge->start) {
|
||||
if (!(pNew = malloc(sizeof(xf86EdgeRec))))
|
||||
if (!(pNew = calloc(1, sizeof(xf86EdgeRec))))
|
||||
break;
|
||||
|
||||
pNew->screen = screen;
|
||||
|
|
|
@ -145,7 +145,7 @@ DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, DGAModePtr modes, int num)
|
|||
pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
|
||||
|
||||
if (!pScreenPriv) {
|
||||
if (!(pScreenPriv = (DGAScreenPtr) malloc(sizeof(DGAScreenRec))))
|
||||
if (!(pScreenPriv = calloc(1, sizeof(DGAScreenRec))))
|
||||
return FALSE;
|
||||
dixSetPrivate(&pScreen->devPrivates, &DGAScreenKeyRec, pScreenPriv);
|
||||
dixScreenHookClose(pScreen, DGACloseScreen);
|
||||
|
@ -399,7 +399,7 @@ xf86SetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet)
|
|||
else
|
||||
return BadValue;
|
||||
|
||||
if (!(device = (DGADevicePtr) malloc(sizeof(DGADeviceRec))))
|
||||
if (!(device = calloc(1, sizeof(DGADeviceRec))))
|
||||
return BadAlloc;
|
||||
|
||||
if (!pScreenPriv->current) {
|
||||
|
@ -663,7 +663,7 @@ DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc)
|
|||
|
||||
pMode = &(pScreenPriv->modes[mode - 1]);
|
||||
|
||||
if (!(pVisual = malloc(sizeof(VisualRec))))
|
||||
if (!(pVisual = calloc(1, sizeof(VisualRec))))
|
||||
return BadAlloc;
|
||||
|
||||
pVisual->vid = FakeClientID(0);
|
||||
|
@ -697,7 +697,7 @@ DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc)
|
|||
pVisual->offsetBlue = BitsClear(pVisual->blueMask);
|
||||
}
|
||||
|
||||
if (!(fvlp = malloc(sizeof(FakedVisualList)))) {
|
||||
if (!(fvlp = calloc(1, sizeof(FakedVisualList)))) {
|
||||
free(pVisual);
|
||||
return BadAlloc;
|
||||
}
|
||||
|
@ -1681,7 +1681,7 @@ ProcXDGASetClientVersion(ClientPtr client)
|
|||
|
||||
REQUEST_SIZE_MATCH(xXDGASetClientVersionReq);
|
||||
if ((pPriv = DGA_GETPRIV(client)) == NULL) {
|
||||
pPriv = malloc(sizeof(DGAPrivRec));
|
||||
pPriv = calloc(1, sizeof(DGAPrivRec));
|
||||
/* XXX Need to look into freeing this */
|
||||
if (!pPriv)
|
||||
return BadAlloc;
|
||||
|
|
|
@ -410,7 +410,6 @@ Bool
|
|||
xf86RandRInit(ScreenPtr pScreen)
|
||||
{
|
||||
rrScrPrivPtr rp;
|
||||
XF86RandRInfoPtr randrp;
|
||||
ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen);
|
||||
|
||||
#ifdef XINERAMA
|
||||
|
@ -424,7 +423,7 @@ xf86RandRInit(ScreenPtr pScreen)
|
|||
if (!dixRegisterPrivateKey(&xf86RandRKeyRec, PRIVATE_SCREEN, 0))
|
||||
return FALSE;
|
||||
|
||||
randrp = malloc(sizeof(XF86RandRInfoRec));
|
||||
XF86RandRInfoPtr randrp = calloc(1, sizeof(XF86RandRInfoRec));
|
||||
if (!randrp)
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ xf86VGAarbiterWrapFunctions(void)
|
|||
if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0))
|
||||
return FALSE;
|
||||
|
||||
if (!(pScreenPriv = malloc(sizeof(VGAarbiterScreenRec))))
|
||||
if (!(pScreenPriv = calloc(1, sizeof(VGAarbiterScreenRec))))
|
||||
return FALSE;
|
||||
|
||||
dixSetPrivate(&pScreen->devPrivates, VGAarbiterScreenKey, pScreenPriv);
|
||||
|
|
|
@ -167,7 +167,7 @@ xf86HandleColormaps(ScreenPtr pScreen,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!(pScreenPriv = malloc(sizeof(CMapScreenRec)))) {
|
||||
if (!(pScreenPriv = calloc(1, sizeof(CMapScreenRec)))) {
|
||||
free(gamma);
|
||||
free(indices);
|
||||
return FALSE;
|
||||
|
@ -254,7 +254,6 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
|
|||
(CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
|
||||
CMapScreenKey);
|
||||
CMapColormapPtr pColPriv;
|
||||
CMapLinkPtr pLink;
|
||||
int numColors;
|
||||
LOCO *colors;
|
||||
|
||||
|
@ -266,7 +265,7 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
|
|||
if (!(colors = xallocarray(numColors, sizeof(LOCO))))
|
||||
return FALSE;
|
||||
|
||||
if (!(pColPriv = malloc(sizeof(CMapColormapRec)))) {
|
||||
if (!(pColPriv = calloc(1, sizeof(CMapColormapRec)))) {
|
||||
free(colors);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -279,7 +278,7 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
|
|||
pColPriv->overscan = -1;
|
||||
|
||||
/* add map to list */
|
||||
pLink = malloc(sizeof(CMapLink));
|
||||
CMapLinkPtr pLink = calloc(1, sizeof(CMapLink));
|
||||
if (pLink) {
|
||||
pLink->cmap = pmap;
|
||||
pLink->next = pScreenPriv->maps;
|
||||
|
|
|
@ -318,7 +318,7 @@ AllocateArea(FBManagerPtr offman,
|
|||
if (((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w))
|
||||
continue;
|
||||
|
||||
link = malloc(sizeof(FBLink));
|
||||
link = calloc(1, sizeof(FBLink));
|
||||
if (!link)
|
||||
return NULL;
|
||||
|
||||
|
@ -765,7 +765,6 @@ AllocateLinear(FBManagerPtr offman, int size, int granularity, void *privData)
|
|||
{
|
||||
ScreenPtr pScreen = offman->pScreen;
|
||||
FBLinearLinkPtr linear = NULL;
|
||||
FBLinearLinkPtr newlink = NULL;
|
||||
int offset, end;
|
||||
|
||||
if (size <= 0)
|
||||
|
@ -793,7 +792,7 @@ AllocateLinear(FBManagerPtr offman, int size, int granularity, void *privData)
|
|||
|
||||
/* break left */
|
||||
if (offset > linear->linear.offset) {
|
||||
newlink = malloc(sizeof(FBLinearLink));
|
||||
FBLinearLinkPtr newlink = calloc(1, sizeof(FBLinearLink));
|
||||
if (!newlink)
|
||||
return NULL;
|
||||
newlink->area = NULL;
|
||||
|
@ -809,7 +808,7 @@ AllocateLinear(FBManagerPtr offman, int size, int granularity, void *privData)
|
|||
|
||||
/* break right */
|
||||
if (size < linear->linear.size) {
|
||||
newlink = malloc(sizeof(FBLinearLink));
|
||||
FBLinearLinkPtr newlink = calloc(1, sizeof(FBLinearLink));
|
||||
if (!newlink)
|
||||
return NULL;
|
||||
newlink->area = NULL;
|
||||
|
@ -859,7 +858,7 @@ localAllocateOffscreenLinear(ScreenPtr pScreen,
|
|||
|
||||
DebugF("NOPE, ALLOCATING AREA\n");
|
||||
|
||||
if (!(link = malloc(sizeof(FBLinearLink))))
|
||||
if (!(link = calloc(1, sizeof(FBLinearLink))))
|
||||
return NULL;
|
||||
|
||||
/* No linear available, so try and pinch some from the XY areas */
|
||||
|
@ -1161,7 +1160,6 @@ xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox)
|
|||
static Bool
|
||||
xf86InitFBManagerRegion(ScreenPtr pScreen, RegionPtr FullRegion)
|
||||
{
|
||||
FBManagerPtr offman;
|
||||
|
||||
if (RegionNil(FullRegion))
|
||||
return FALSE;
|
||||
|
@ -1172,7 +1170,7 @@ xf86InitFBManagerRegion(ScreenPtr pScreen, RegionPtr FullRegion)
|
|||
if (!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
|
||||
return FALSE;
|
||||
|
||||
offman = malloc(sizeof(FBManager));
|
||||
FBManagerPtr offman = calloc(1, sizeof(FBManager));
|
||||
if (!offman)
|
||||
return FALSE;
|
||||
|
||||
|
@ -1210,7 +1208,7 @@ xf86InitFBManagerLinear(ScreenPtr pScreen, int offset, int size)
|
|||
|
||||
offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates,
|
||||
xf86FBScreenKey);
|
||||
offman->LinearAreas = malloc(sizeof(FBLinearLink));
|
||||
offman->LinearAreas = calloc(1, sizeof(FBLinearLink));
|
||||
if (!offman->LinearAreas)
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -1358,7 +1358,7 @@ xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip,
|
|||
}
|
||||
if (vendor == match_vendor && chip == match_chip) {
|
||||
tmpMatch =
|
||||
(char *) malloc(sizeof(char) *
|
||||
(char *) calloc(1, sizeof(char) *
|
||||
strlen(direntry->d_name) - 3);
|
||||
if (!tmpMatch) {
|
||||
LogMessageVerb(X_ERROR, 1,
|
||||
|
|
|
@ -86,7 +86,7 @@ xf86SbusProbe(void)
|
|||
char fbDevName[32];
|
||||
sbusDevicePtr psdp, *psdpp;
|
||||
|
||||
xf86SbusInfo = malloc(sizeof(psdp));
|
||||
xf86SbusInfo = calloc(1, sizeof(psdp));
|
||||
*xf86SbusInfo = NULL;
|
||||
for (i = 0; i < 32; i++) {
|
||||
snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i);
|
||||
|
|
|
@ -247,7 +247,7 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
|
|||
|
||||
PortResource = XvGetRTPort();
|
||||
|
||||
ScreenPriv = malloc(sizeof(XF86XVScreenRec));
|
||||
ScreenPriv = calloc(1, sizeof(XF86XVScreenRec));
|
||||
dixSetPrivate(&pScreen->devPrivates, &XF86XVScreenPrivateKey, ScreenPriv);
|
||||
|
||||
if (!ScreenPriv)
|
||||
|
|
|
@ -166,7 +166,7 @@ xf86XvMCScreenInit(ScreenPtr pScreen,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) {
|
||||
if (!(pScreenPriv = calloc(1, sizeof(xf86XvMCScreenRec)))) {
|
||||
free(pAdapt);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -64,12 +64,10 @@
|
|||
XISBuffer *
|
||||
XisbNew(int fd, ssize_t size)
|
||||
{
|
||||
XISBuffer *b;
|
||||
|
||||
b = malloc(sizeof(XISBuffer));
|
||||
XISBuffer *b = calloc(1, sizeof(XISBuffer));
|
||||
if (!b)
|
||||
return NULL;
|
||||
b->buf = malloc((sizeof(unsigned char) * size));
|
||||
b->buf = calloc(sizeof(unsigned char), size);
|
||||
if (!b->buf) {
|
||||
free(b);
|
||||
return NULL;
|
||||
|
|
|
@ -93,7 +93,7 @@ find_header(unsigned char *block)
|
|||
static unsigned char *
|
||||
resort(unsigned char *s_block)
|
||||
{
|
||||
unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
|
||||
unsigned char *d_ptr, *d_end, *s_ptr, *s_end;
|
||||
unsigned char tmp;
|
||||
|
||||
s_ptr = find_header(s_block);
|
||||
|
@ -101,7 +101,7 @@ resort(unsigned char *s_block)
|
|||
return NULL;
|
||||
s_end = s_block + EDID1_LEN;
|
||||
|
||||
d_new = malloc(EDID1_LEN);
|
||||
unsigned char *d_new = calloc(1, EDID1_LEN);
|
||||
if (!d_new)
|
||||
return NULL;
|
||||
d_end = d_new + EDID1_LEN;
|
||||
|
@ -189,7 +189,7 @@ FetchEDID_DDC1(register ScrnInfoPtr pScrn,
|
|||
int count = NUM;
|
||||
unsigned int *ptr, *xp;
|
||||
|
||||
ptr = xp = malloc(sizeof(int) * NUM);
|
||||
ptr = xp = calloc(NUM, sizeof(int));
|
||||
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
|
@ -416,9 +416,7 @@ xf86DoEEDID(ScrnInfoPtr pScrn, I2CBusPtr pBus, Bool complete)
|
|||
|
||||
/* Default DDC and DDC2 to enabled. */
|
||||
Bool noddc = FALSE, noddc2 = FALSE;
|
||||
OptionInfoPtr options;
|
||||
|
||||
options = malloc(sizeof(DDCOptions));
|
||||
OptionInfoPtr options = calloc(1, sizeof(DDCOptions));
|
||||
if (!options)
|
||||
return NULL;
|
||||
memcpy(options, DDCOptions, sizeof(DDCOptions));
|
||||
|
|
|
@ -1334,7 +1334,7 @@ DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
|
|||
}
|
||||
else {
|
||||
/* allocate a DRI Window Private record */
|
||||
if (!(pDRIDrawablePriv = malloc(sizeof(DRIDrawablePrivRec)))) {
|
||||
if (!(pDRIDrawablePriv = calloc(1, sizeof(DRIDrawablePrivRec)))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -236,12 +236,11 @@ static DRI2DrawablePtr
|
|||
DRI2AllocateDrawable(DrawablePtr pDraw)
|
||||
{
|
||||
DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen);
|
||||
DRI2DrawablePtr pPriv;
|
||||
CARD64 ust;
|
||||
WindowPtr pWin;
|
||||
PixmapPtr pPixmap;
|
||||
|
||||
pPriv = malloc(sizeof *pPriv);
|
||||
DRI2DrawablePtr pPriv = calloc(1, sizeof *pPriv);
|
||||
if (pPriv == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -328,9 +327,7 @@ static int
|
|||
DRI2AddDrawableRef(DRI2DrawablePtr pPriv, XID id, XID dri2_id,
|
||||
DRI2InvalidateProcPtr invalidate, void *priv)
|
||||
{
|
||||
DRI2DrawableRefPtr ref;
|
||||
|
||||
ref = malloc(sizeof *ref);
|
||||
DRI2DrawableRefPtr ref = calloc(1, sizeof *ref);
|
||||
if (ref == NULL)
|
||||
return BadAlloc;
|
||||
|
||||
|
|
|
@ -88,7 +88,6 @@ struct ms_dri2_resource {
|
|||
static struct ms_dri2_resource *
|
||||
ms_get_resource(XID id, RESTYPE type)
|
||||
{
|
||||
struct ms_dri2_resource *resource;
|
||||
void *ptr;
|
||||
|
||||
ptr = NULL;
|
||||
|
@ -96,7 +95,7 @@ ms_get_resource(XID id, RESTYPE type)
|
|||
if (ptr)
|
||||
return ptr;
|
||||
|
||||
resource = malloc(sizeof(*resource));
|
||||
struct ms_dri2_resource *resource = calloc(1, sizeof(*resource));
|
||||
if (resource == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -1328,7 +1328,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
|
|||
|
||||
/* Process the options */
|
||||
xf86CollectOptions(pScrn, NULL);
|
||||
if (!(ms->drmmode.Options = malloc(sizeof(Options))))
|
||||
if (!(ms->drmmode.Options = calloc(1, sizeof(Options))))
|
||||
return FALSE;
|
||||
memcpy(ms->drmmode.Options, Options, sizeof(Options));
|
||||
xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->drmmode.Options);
|
||||
|
|
|
@ -410,7 +410,7 @@ drmmode_prop_info_copy(drmmode_prop_info_ptr dst,
|
|||
continue;
|
||||
|
||||
dst[i].enum_values =
|
||||
malloc(src[i].num_enum_values *
|
||||
calloc(src[i].num_enum_values,
|
||||
sizeof(*dst[i].enum_values));
|
||||
if (!dst[i].enum_values)
|
||||
goto err;
|
||||
|
@ -4121,7 +4121,7 @@ drmmode_crtc_upgrade_lut(xf86CrtcPtr crtc, int num)
|
|||
|
||||
if (size != crtc->gamma_size) {
|
||||
ScrnInfoPtr pScrn = crtc->scrn;
|
||||
uint16_t *gamma = malloc(3 * size * sizeof(uint16_t));
|
||||
uint16_t *gamma = calloc(3 * size, sizeof(uint16_t));
|
||||
|
||||
if (gamma) {
|
||||
free(crtc->gamma_red);
|
||||
|
|
|
@ -207,7 +207,7 @@ xf86HandleInt10Options(ScrnInfoPtr pScrn, int entityIndex)
|
|||
configOptions = pEnt->device->options;
|
||||
|
||||
if (configOptions) {
|
||||
if (!(options = (OptionInfoPtr) malloc(sizeof(INT10Options))))
|
||||
if (!(options = (OptionInfoPtr) calloc(1, sizeof(INT10Options))))
|
||||
return NULL;
|
||||
|
||||
(void) memcpy(options, INT10Options, sizeof(INT10Options));
|
||||
|
|
|
@ -505,8 +505,6 @@ VBEGetVBEMode(vbeInfoPtr pVbe, int *mode)
|
|||
VbeModeInfoBlock *
|
||||
VBEGetModeInfo(vbeInfoPtr pVbe, int mode)
|
||||
{
|
||||
VbeModeInfoBlock *block = NULL;
|
||||
|
||||
memset(pVbe->memory, 0, sizeof(VbeModeInfoBlock));
|
||||
|
||||
/*
|
||||
|
@ -530,7 +528,7 @@ VBEGetModeInfo(vbeInfoPtr pVbe, int mode)
|
|||
if (R16(pVbe->pInt10->ax) != 0x4f)
|
||||
return NULL;
|
||||
|
||||
block = malloc(sizeof(VbeModeInfoBlock));
|
||||
VbeModeInfoBlock *block = calloc(1, sizeof(VbeModeInfoBlock));
|
||||
if (block)
|
||||
memcpy(block, pVbe->memory, sizeof(*block));
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ InitPathList(const char *path)
|
|||
free(fullpath);
|
||||
return NULL;
|
||||
}
|
||||
list[n] = malloc(len + 1);
|
||||
list[n] = calloc(1, len + 1);
|
||||
if (!list[n]) {
|
||||
FreeStringList(list);
|
||||
free(fullpath);
|
||||
|
@ -398,7 +398,7 @@ LoaderListDir(const char *subdir, const char **patternlist)
|
|||
closedir(d);
|
||||
goto bail;
|
||||
}
|
||||
listing[n] = malloc(len + 1);
|
||||
listing[n] = calloc(1, len + 1);
|
||||
if (!listing[n]) {
|
||||
FreeStringList(listing);
|
||||
closedir(d);
|
||||
|
@ -725,7 +725,7 @@ LoadModule(const char *module, void *options, const XF86ModReqInfo *modreq,
|
|||
|
||||
pathlist = defaultPathList;
|
||||
if (!pathlist) {
|
||||
/* This could be a malloc failure too */
|
||||
/* This could be a calloc failure too */
|
||||
if (errmaj)
|
||||
*errmaj = LDR_BADUSAGE;
|
||||
goto LoadModule_fail;
|
||||
|
@ -964,7 +964,6 @@ LoaderErrorMsg(const char *name, const char *modname, int errmaj, int errmin)
|
|||
static char *
|
||||
LoaderGetCanonicalName(const char *modname, PatternPtr patterns)
|
||||
{
|
||||
char *str;
|
||||
const char *s;
|
||||
int len;
|
||||
PatternPtr p;
|
||||
|
@ -981,7 +980,7 @@ LoaderGetCanonicalName(const char *modname, PatternPtr patterns)
|
|||
for (p = patterns; p->pattern; p++)
|
||||
if (regexec(&p->rex, s, 2, match, 0) == 0 && match[1].rm_so != -1) {
|
||||
len = match[1].rm_eo - match[1].rm_so;
|
||||
str = malloc(len + 1);
|
||||
char *str = calloc(1, len + 1);
|
||||
if (!str)
|
||||
return NULL;
|
||||
strncpy(str, s + match[1].rm_so, len);
|
||||
|
|
|
@ -649,7 +649,7 @@ xf86_cursors_init(ScreenPtr screen, int max_width, int max_height, int flags)
|
|||
if (!cursor_info)
|
||||
return FALSE;
|
||||
|
||||
xf86_config->cursor_image = malloc(max_width * max_height * 4);
|
||||
xf86_config->cursor_image = calloc(max_width * max_height, 4);
|
||||
|
||||
if (!xf86_config->cursor_image) {
|
||||
xf86DestroyCursorInfoRec(cursor_info);
|
||||
|
|
|
@ -847,7 +847,6 @@ Bool
|
|||
xf86RandR12Init(ScreenPtr pScreen)
|
||||
{
|
||||
rrScrPrivPtr rp;
|
||||
XF86RandRInfoPtr randrp;
|
||||
|
||||
#ifdef XINERAMA
|
||||
/* XXX disable RandR when using Xinerama */
|
||||
|
@ -865,7 +864,7 @@ xf86RandR12Init(ScreenPtr pScreen)
|
|||
if (!dixRegisterPrivateKey(&xf86RandR12KeyRec, PRIVATE_SCREEN, 0))
|
||||
return FALSE;
|
||||
|
||||
randrp = malloc(sizeof(XF86RandRInfoRec));
|
||||
XF86RandRInfoPtr randrp = calloc(1, sizeof(XF86RandRInfoRec));
|
||||
if (!randrp)
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -457,7 +457,7 @@ xf86CrtcRotate(xf86CrtcPtr crtc)
|
|||
#ifdef RANDR_12_INTERFACE
|
||||
if (transform) {
|
||||
if (transform->nparams) {
|
||||
new_params = malloc(transform->nparams * sizeof(xFixed));
|
||||
new_params = calloc(transform->nparams, sizeof(xFixed));
|
||||
if (new_params) {
|
||||
memcpy(new_params, transform->params,
|
||||
transform->nparams * sizeof(xFixed));
|
||||
|
|
|
@ -205,7 +205,7 @@ sparcPromInit(void)
|
|||
promFd = open("/dev/openprom", O_RDONLY, 0);
|
||||
if (promFd == -1)
|
||||
return -1;
|
||||
promOpio = (struct openpromio *) malloc(4096);
|
||||
promOpio = (struct openpromio *) calloc(1, 4096);
|
||||
if (!promOpio) {
|
||||
sparcPromClose();
|
||||
return -1;
|
||||
|
@ -526,11 +526,9 @@ promWalkNode2Pathname(char *path, int parent, int node, int searchNode,
|
|||
char *
|
||||
sparcPromNode2Pathname(sbusPromNodePtr pnode)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (!pnode->node)
|
||||
return NULL;
|
||||
ret = malloc(4096);
|
||||
char *ret = calloc(1, 4096);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
if (promWalkNode2Pathname
|
||||
|
@ -600,10 +598,10 @@ int
|
|||
sparcPromPathname2Node(const char *pathName)
|
||||
{
|
||||
int i;
|
||||
char *name, *regstr, *p;
|
||||
char *regstr, *p;
|
||||
|
||||
i = strlen(pathName);
|
||||
name = malloc(i + 2);
|
||||
char *name = calloc(1, i + 2);
|
||||
if (!name)
|
||||
return 0;
|
||||
strcpy(name, pathName);
|
||||
|
|
|
@ -155,9 +155,7 @@ enum MatchType {
|
|||
static void
|
||||
add_group_entry(struct xorg_list *head, char **values, enum MatchType type)
|
||||
{
|
||||
xf86MatchGroup *group;
|
||||
|
||||
group = malloc(sizeof(*group));
|
||||
xf86MatchGroup *group = calloc(1, sizeof(xf86MatchGroup));
|
||||
if (group) {
|
||||
group->is_negated = (type == MATCH_NEGATED);
|
||||
group->values = values;
|
||||
|
|
|
@ -81,9 +81,7 @@ xf86freeOutputClassList(XF86ConfOutputClassPtr ptr)
|
|||
static void
|
||||
add_group_entry(struct xorg_list *head, char **values)
|
||||
{
|
||||
xf86MatchGroup *group;
|
||||
|
||||
group = malloc(sizeof(*group));
|
||||
xf86MatchGroup *group = calloc(1, sizeof(xf86MatchGroup));
|
||||
if (group) {
|
||||
group->values = values;
|
||||
xorg_list_add(&group->entry, head);
|
||||
|
|
|
@ -118,20 +118,20 @@ xf86getNextLine(void)
|
|||
|
||||
/*
|
||||
* reallocate the string if it was grown last time (i.e., is no
|
||||
* longer CONFIG_BUF_LEN); we malloc the new strings first, so
|
||||
* that if either of the mallocs fail, we can fall back on the
|
||||
* longer CONFIG_BUF_LEN); we calloc the new strings first, so
|
||||
* that if either of the callocs fail, we can fall back on the
|
||||
* existing buffer allocations
|
||||
*/
|
||||
|
||||
if (configBufLen != CONFIG_BUF_LEN) {
|
||||
|
||||
tmpConfigBuf = malloc(CONFIG_BUF_LEN);
|
||||
tmpConfigRBuf = malloc(CONFIG_BUF_LEN);
|
||||
tmpConfigBuf = calloc(1, CONFIG_BUF_LEN);
|
||||
tmpConfigRBuf = calloc(1, CONFIG_BUF_LEN);
|
||||
|
||||
if (!tmpConfigBuf || !tmpConfigRBuf) {
|
||||
|
||||
/*
|
||||
* at least one of the mallocs failed; keep the old buffers
|
||||
* at least one of the callocs failed; keep the old buffers
|
||||
* and free any partial allocations
|
||||
*/
|
||||
|
||||
|
@ -142,7 +142,7 @@ xf86getNextLine(void)
|
|||
else {
|
||||
|
||||
/*
|
||||
* malloc succeeded; free the old buffers and use the new
|
||||
* calloc succeeded; free the old buffers and use the new
|
||||
* buffers
|
||||
*/
|
||||
|
||||
|
@ -393,7 +393,7 @@ xf86getToken(const xf86ConfigSymTabRec * tab)
|
|||
}
|
||||
while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0'));
|
||||
configRBuf[i] = '\0';
|
||||
xf86_lex_val.str = malloc(strlen(configRBuf) + 1);
|
||||
xf86_lex_val.str = calloc(1, strlen(configRBuf) + 1);
|
||||
strcpy(xf86_lex_val.str, configRBuf); /* private copy ! */
|
||||
return STRING;
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ DoSubstitution(const char *template, const char *cmdline, const char *projroot,
|
|||
break;
|
||||
case 'H':
|
||||
if (!hostname) {
|
||||
if ((hostname = malloc(MAXHOSTNAMELEN + 1))) {
|
||||
if ((hostname = calloc(1, MAXHOSTNAMELEN + 1))) {
|
||||
if (gethostname(hostname, MAXHOSTNAMELEN) == 0) {
|
||||
hostname[MAXHOSTNAMELEN] = '\0';
|
||||
}
|
||||
|
@ -771,7 +771,6 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
|
|||
Bool warnOnce = FALSE;
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
char *path;
|
||||
FILE *file;
|
||||
|
||||
if (numFiles >= CONFIG_MAX_FILES) {
|
||||
|
@ -782,7 +781,7 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
|
|||
continue;
|
||||
}
|
||||
|
||||
path = malloc(PATH_MAX + 1);
|
||||
char *path = calloc(1, PATH_MAX + 1);
|
||||
snprintf(path, PATH_MAX + 1, "%s/%s", dirpath, list[i]->d_name);
|
||||
file = fopen(path, "r");
|
||||
if (!file) {
|
||||
|
@ -859,8 +858,8 @@ xf86initConfigFiles(void)
|
|||
configLineNo = 0;
|
||||
pushToken = LOCK_TOKEN;
|
||||
|
||||
configBuf = malloc(CONFIG_BUF_LEN);
|
||||
configRBuf = malloc(CONFIG_BUF_LEN);
|
||||
configBuf = calloc(1, CONFIG_BUF_LEN);
|
||||
configRBuf = calloc(1, CONFIG_BUF_LEN);
|
||||
configBuf[0] = '\0'; /* sanity ... */
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ ShadowFBInit2(ScreenPtr pScreen,
|
|||
if (!dixRegisterPrivateKey(&ShadowScreenKeyRec, PRIVATE_SCREEN, 0))
|
||||
return FALSE;
|
||||
|
||||
if (!(pPriv = (ShadowScreenPtr) malloc(sizeof(ShadowScreenRec))))
|
||||
if (!(pPriv = (ShadowScreenPtr) calloc(1, sizeof(ShadowScreenRec))))
|
||||
return FALSE;
|
||||
|
||||
dixSetPrivate(&pScreen->devPrivates, &ShadowScreenKeyRec, pPriv);
|
||||
|
|
|
@ -953,21 +953,21 @@ vgaHWSaveFonts(ScrnInfoPtr scrninfp, vgaRegPtr save)
|
|||
hwp->writeGr(hwp, 0x06, 0x05); /* set graphics */
|
||||
|
||||
#if SAVE_FONT1
|
||||
if (hwp->FontInfo1 || (hwp->FontInfo1 = malloc(FONT_AMOUNT))) {
|
||||
if (hwp->FontInfo1 || (hwp->FontInfo1 = calloc(1, FONT_AMOUNT))) {
|
||||
hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */
|
||||
hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */
|
||||
slowbcopy_frombus(hwp->Base, hwp->FontInfo1, FONT_AMOUNT);
|
||||
}
|
||||
#endif /* SAVE_FONT1 */
|
||||
#if SAVE_FONT2
|
||||
if (hwp->FontInfo2 || (hwp->FontInfo2 = malloc(FONT_AMOUNT))) {
|
||||
if (hwp->FontInfo2 || (hwp->FontInfo2 = calloc(1, FONT_AMOUNT))) {
|
||||
hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */
|
||||
hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */
|
||||
slowbcopy_frombus(hwp->Base, hwp->FontInfo2, FONT_AMOUNT);
|
||||
}
|
||||
#endif /* SAVE_FONT2 */
|
||||
#if SAVE_TEXT
|
||||
if (hwp->TextInfo || (hwp->TextInfo = malloc(2 * TEXT_AMOUNT))) {
|
||||
if (hwp->TextInfo || (hwp->TextInfo = calloc(2, TEXT_AMOUNT))) {
|
||||
hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */
|
||||
hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */
|
||||
slowbcopy_frombus(hwp->Base, hwp->TextInfo, TEXT_AMOUNT);
|
||||
|
|
Loading…
Reference in New Issue