diff options
author | Marek Olšák <[email protected]> | 2011-09-10 18:42:49 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2011-09-10 19:40:36 +0200 |
commit | 9222c497f9e73ae19b1b4dab1d9c9b4aa797b11d (patch) | |
tree | 9615b744b48e31c2e7d81c196e180eae4e7534e8 | |
parent | aa77df135571978bcda5a3254f67ca7e307b1960 (diff) |
mesa: fix more valgrind warnings
==27540== Invalid read of size 4
==27540== at 0x96277B7: _mesa_make_extension_string (string3.h:144)
==27540== by 0x9604E78: _mesa_make_current (context.c:1514)
==27540== by 0x9602A8B: st_api_make_current (st_manager.c:789)
==27540== by 0x45406E7: ???
==27540== Address 0xad35b30 is 3,688 bytes inside a block of size 3,691 alloc'd
==27540== at 0x4025315: calloc (vg_replace_malloc.c:467)
==27540== by 0x9627641: _mesa_make_extension_string (extensions.c:910)
==27540== by 0x9604E78: _mesa_make_current (context.c:1514)
==27540== by 0x9602A8B: st_api_make_current (st_manager.c:789)
==27540== by 0x45406E7: ???
And:
==28351== Invalid write of size 2
==28351== at 0x4C087CC: _mesa_make_extension_string (string3.h:144)
==28351== by 0x4BE6198: _mesa_make_current (context.c:1514)
==28351== by 0x4BD4CAB: st_api_make_current (st_manager.c:789)
==28351== Address 0x48dd1f3 is 19 bytes inside a block of size 20 alloc'd
==28351== at 0x4025315: calloc (vg_replace_malloc.c:467)
==28351== by 0x4C08711: _mesa_make_extension_string (extensions.c:778)
==28351== by 0x4BE6198: _mesa_make_current (context.c:1514)
==28351== by 0x4BD4CAB: st_api_make_current (st_manager.c:789)
==28351==
==28351== Invalid read of size 4
==28351== at 0x4C087EC: _mesa_make_extension_string (extensions.c:806)
==28351== by 0x4BE6198: _mesa_make_current (context.c:1514)
==28351== by 0x4BD4CAB: st_api_make_current (st_manager.c:789)
==28351== Address 0x48dd1f4 is 0 bytes after a block of size 20 alloc'd
==28351== at 0x4025315: calloc (vg_replace_malloc.c:467)
==28351== by 0x4C08711: _mesa_make_extension_string (extensions.c:778)
==28351== by 0x4BE6198: _mesa_make_current (context.c:1514)
==28351== by 0x4BD4CAB: st_api_make_current (st_manager.c:789)
The first part adds 2, because ' ' and '\0' may be written at the end
of the buffer.
-rw-r--r-- | src/mesa/main/extensions.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index aceddaa3ef2..9cec15b5817 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -37,6 +37,8 @@ #include "mfeatures.h" #include "mtypes.h" +#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1)) + enum { DISABLE = 0, GL = 1 << API_OPENGL, @@ -773,7 +775,7 @@ get_extension_override( struct gl_context *ctx ) } /* extra_exts: List of unrecognized extensions. */ - extra_exts = calloc(strlen(env_const), sizeof(char)); + extra_exts = calloc(ALIGN(strlen(env_const) + 2, 4), sizeof(char)); /* Copy env_const because strtok() is destructive. */ env = strdup(env_const); @@ -907,7 +909,7 @@ _mesa_make_extension_string(struct gl_context *ctx) if (extra_extensions != NULL) length += 1 + strlen(extra_extensions); /* +1 for space */ - exts = (char *) calloc(length + 1, sizeof(char)); + exts = (char *) calloc(ALIGN(length + 1, 4), sizeof(char)); if (exts == NULL) { free(extra_extensions); return NULL; |