From 900ddb69a264926c4c2edaa60c8440d386d5e0db Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 10 Apr 2025 19:22:29 +0200 Subject: [PATCH] glamor: 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 --- glamor/glamor_core.c | 6 ++---- glamor/glamor_font.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c index 6e83a43ed..43d859d1f 100644 --- a/glamor/glamor_core.c +++ b/glamor/glamor_core.c @@ -63,11 +63,10 @@ glamor_compile_glsl_prog(GLenum type, const char *source) glCompileShader(prog); glGetShaderiv(prog, GL_COMPILE_STATUS, &ok); if (!ok) { - GLchar *info; GLint size; glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size); - info = malloc(size); + GLchar *info = calloc(1, size); if (info) { glGetShaderInfoLog(prog, size, NULL, info); ErrorF("Failed to compile %s: %s\n", @@ -103,11 +102,10 @@ glamor_link_glsl_prog(ScreenPtr screen, GLint prog, const char *format, ...) glLinkProgram(prog); glGetProgramiv(prog, GL_LINK_STATUS, &ok); if (!ok) { - GLchar *info; GLint size; glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size); - info = malloc(size); + GLchar *info = calloc(1, size); glGetProgramInfoLog(prog, size, NULL, info); ErrorF("Failed to link: %s\n", info); diff --git a/glamor/glamor_font.c b/glamor/glamor_font.c index 9b26180e9..42ae70b1d 100644 --- a/glamor/glamor_font.c +++ b/glamor/glamor_font.c @@ -51,7 +51,6 @@ glamor_font_get(ScreenPtr screen, FontPtr font) unsigned char c[2]; CharInfoPtr glyph; unsigned long count; - char *bits; if (!glamor_glsl_has_ints(glamor_priv)) return NULL; @@ -102,7 +101,7 @@ glamor_font_get(ScreenPtr screen, FontPtr font) /* fallback if we don't fit inside a texture */ return NULL; } - bits = malloc(overall_width * overall_height); + char *bits = calloc(overall_width, overall_height); if (!bits) return NULL;