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 <info@metux.net>
This commit is contained in:
parent
8c05f4db0a
commit
900ddb69a2
|
@ -63,11 +63,10 @@ glamor_compile_glsl_prog(GLenum type, const char *source)
|
||||||
glCompileShader(prog);
|
glCompileShader(prog);
|
||||||
glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
|
glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
GLchar *info;
|
|
||||||
GLint size;
|
GLint size;
|
||||||
|
|
||||||
glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
|
glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
|
||||||
info = malloc(size);
|
GLchar *info = calloc(1, size);
|
||||||
if (info) {
|
if (info) {
|
||||||
glGetShaderInfoLog(prog, size, NULL, info);
|
glGetShaderInfoLog(prog, size, NULL, info);
|
||||||
ErrorF("Failed to compile %s: %s\n",
|
ErrorF("Failed to compile %s: %s\n",
|
||||||
|
@ -103,11 +102,10 @@ glamor_link_glsl_prog(ScreenPtr screen, GLint prog, const char *format, ...)
|
||||||
glLinkProgram(prog);
|
glLinkProgram(prog);
|
||||||
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
|
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
GLchar *info;
|
|
||||||
GLint size;
|
GLint size;
|
||||||
|
|
||||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
|
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
|
||||||
info = malloc(size);
|
GLchar *info = calloc(1, size);
|
||||||
|
|
||||||
glGetProgramInfoLog(prog, size, NULL, info);
|
glGetProgramInfoLog(prog, size, NULL, info);
|
||||||
ErrorF("Failed to link: %s\n", info);
|
ErrorF("Failed to link: %s\n", info);
|
||||||
|
|
|
@ -51,7 +51,6 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
|
||||||
unsigned char c[2];
|
unsigned char c[2];
|
||||||
CharInfoPtr glyph;
|
CharInfoPtr glyph;
|
||||||
unsigned long count;
|
unsigned long count;
|
||||||
char *bits;
|
|
||||||
|
|
||||||
if (!glamor_glsl_has_ints(glamor_priv))
|
if (!glamor_glsl_has_ints(glamor_priv))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -102,7 +101,7 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
|
||||||
/* fallback if we don't fit inside a texture */
|
/* fallback if we don't fit inside a texture */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bits = malloc(overall_width * overall_height);
|
char *bits = calloc(overall_width, overall_height);
|
||||||
if (!bits)
|
if (!bits)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue