Mesa (main): mesa: s/malloc/calloc/ to silence a warning

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu May 6 22:43:47 UTC 2021


Module: Mesa
Branch: main
Commit: 90cbab7cae5b6fda5646a8037bff6e66a3c73d66
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=90cbab7cae5b6fda5646a8037bff6e66a3c73d66

Author: Adam Jackson <ajax at redhat.com>
Date:   Thu May  6 13:26:10 2021 -0400

mesa: s/malloc/calloc/ to silence a warning

gcc 11 warns:

[846/1506] Compiling C object src/mesa/libmesa_common.a.p/main_shaderapi.c.o
In function ‘shader_source’,
    inlined from ‘_mesa_ShaderSource_no_error’ at ../src/mesa/main/shaderapi.c:2137:4:
../src/mesa/main/shaderapi.c:2095:25: warning: ‘*offsets_10 + _130’ may be used uninitialized [-Wmaybe-uninitialized]
 2095 |    totalLength = offsets[count - 1] + 2;

I can't really see how it's getting to that conclusion, but allocating
`offsets` with calloc is both natural to do here and guarantees
initialization.

Reviewed-by: Matt Turner <mattst88 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10671>

---

 src/mesa/main/shaderapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index bf372dceecd..88544179f6e 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -2066,7 +2066,7 @@ shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count,
     * This array holds offsets of where the appropriate string ends, thus the
     * last element will be set to the total length of the source code.
     */
-   offsets = malloc(count * sizeof(GLint));
+   offsets = calloc(count, sizeof(GLint));
    if (offsets == NULL) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
       return;



More information about the mesa-commit mailing list