xnest: 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:
Enrico Weigelt, metux IT consult 2025-04-10 20:05:27 +02:00
parent d8e6511b1b
commit 8f26a2f6a7
2 changed files with 4 additions and 6 deletions

View File

@ -37,7 +37,6 @@ int xnestFontPrivateIndex;
Bool
xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont)
{
void *priv;
Atom name_atom, value_atom;
int nprops;
FontPropPtr props;
@ -66,7 +65,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont)
if (!name)
return FALSE;
priv = (void *) malloc(sizeof(xnestPrivFont));
void *priv = calloc(1, sizeof(xnestPrivFont));
xfont2_font_set_private(pFont, xnestFontPrivateIndex, priv);
xnestFontPriv(pFont)->font_struct = XLoadQueryFont(xnestDisplay, name);

View File

@ -167,10 +167,10 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
visuals = xallocarray(xnestNumVisuals, sizeof(VisualRec));
numVisuals = 0;
depths = (DepthPtr) malloc(MAXDEPTH * sizeof(DepthRec));
depths = calloc(MAXDEPTH, sizeof(DepthRec));
depths[0].depth = 1;
depths[0].numVids = 0;
depths[0].vids = (VisualID *) malloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
depths[0].vids = calloc(MAXVISUALSPERDEPTH, sizeof(VisualID));
numDepths = 1;
for (i = 0; i < xnestNumVisuals; i++) {
@ -217,8 +217,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
depthIndex = numDepths;
depths[depthIndex].depth = xnestVisuals[i].depth;
depths[depthIndex].numVids = 0;
depths[depthIndex].vids =
(VisualID *) malloc(MAXVISUALSPERDEPTH * sizeof(VisualID));
depths[depthIndex].vids = calloc(MAXVISUALSPERDEPTH, sizeof(VisualID));
numDepths++;
}
if (depths[depthIndex].numVids >= MAXVISUALSPERDEPTH) {