In commit
32f2fd1c5d6088692551c80352b7d6fa35b0cd09, several calls to
_mesa_calloc(x) were replaced with calls to calloc(1, x). This is strictly
equivalent to what the code was doing previously.
But for cases where "x" involves multiplication, now that we are explicitly
using the two-argument calloc, we can do one step better and replace:
calloc(1, A * B);
with:
calloc(A, B);
The advantage of the latter is that calloc will detect any overflow that would
have resulted from the multiplication and will fail the allocation, (whereas
the former would return a small allocation). So this fix can change
potentially exploitable buffer overruns into segmentation faults.
Reviewed-by: Matt Turner <mattst88@gmail.com>
goto fail;
}
- ptr = dwords = calloc(1, 4 * info->sizedwords);
+ ptr = dwords = calloc(4, info->sizedwords);
/* second pass, emit CF program in pairs: */
for (i = 0; i < shader->cfs_count; i += 2) {
*/
info->sizedwords = 2 * align(shader->instrs_count, 4);
- ptr = dwords = calloc(1, 4 * info->sizedwords);
+ ptr = dwords = calloc(4, info->sizedwords);
for (i = 0; i < shader->instrs_count; i++) {
struct ir3_instruction *instr = shader->instrs[i];
bc->ndw = cf->addr + cf->ndw;
}
free(bc->bytecode);
- bc->bytecode = calloc(1, bc->ndw * 4);
+ bc->bytecode = calloc(4, bc->ndw);
if (bc->bytecode == NULL)
return -ENOMEM;
LIST_FOR_EACH_ENTRY(cf, &bc->cf, list) {
struct _glapi_table *
_glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
- struct _glapi_table *disp = calloc(1, _glapi_get_dispatch_table_size() * sizeof(_glapi_proc));
+ struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(_glapi_proc));
char symboln[512];
if(!disp)
is_srgb = _mesa_get_format_color_encoding(format) == GL_SRGB;
num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes;
- configs = calloc(1, (num_modes + 1) * sizeof *configs);
+ configs = calloc(num_modes + 1, sizeof *configs);
if (configs == NULL)
return NULL;
GLuint size, i;
size = cache->size * 3;
- items = calloc(1, size * sizeof(*items));
+ items = calloc(size, sizeof(*items));
for (i = 0; i < cache->size; i++)
for (c = cache->items[i]; c; c = next) {
cache->size = 7;
cache->n_items = 0;
cache->items =
- calloc(1, cache->size * sizeof(struct brw_cache_item *));
+ calloc(cache->size, sizeof(struct brw_cache_item *));
cache->bo = drm_intel_bo_alloc(brw->bufmgr,
"program cache",
a start */
for (i = 0; i < MAX_NUM_PASSES_ATI; i++) {
ctx->ATIFragmentShader.Current->Instructions[i] =
- calloc(1, sizeof(struct atifs_instruction) *
- (MAX_NUM_INSTRUCTIONS_PER_PASS_ATI));
+ calloc(sizeof(struct atifs_instruction),
+ MAX_NUM_INSTRUCTIONS_PER_PASS_ATI);
ctx->ATIFragmentShader.Current->SetupInst[i] =
- calloc(1, sizeof(struct atifs_setupinst) *
- (MAX_NUM_FRAGMENT_REGISTERS_ATI));
+ calloc(sizeof(struct atifs_setupinst),
+ MAX_NUM_FRAGMENT_REGISTERS_ATI);
}
/* can't rely on calloc for initialization as it's possible to redefine a shader (?) */
_mesa_alloc_instructions(GLuint numInst)
{
return
- calloc(1, numInst * sizeof(struct prog_instruction));
+ calloc(numInst, sizeof(struct prog_instruction));
}
}
removeInst =
- calloc(1, prog->NumInstructions * sizeof(GLboolean));
+ calloc(prog->NumInstructions, sizeof(GLboolean));
/* Determine which temps are read and written */
for (i = 0; i < prog->NumInstructions; i++) {
GLuint i, arg, rem = 0;
removeInst =
- calloc(1, prog->NumInstructions * sizeof(GLboolean));
+ calloc(prog->NumInstructions, sizeof(GLboolean));
for (i = 0; i < prog->NumInstructions; i++) {
const struct prog_instruction *inst = prog->Instructions + i;
}
removeInst =
- calloc(1, prog->NumInstructions * sizeof(GLboolean));
+ calloc(prog->NumInstructions, sizeof(GLboolean));
/*
* Look for sequences such as this:
/* alloc arrays */
p->Parameters = (struct gl_program_parameter *)
- calloc(1, size * sizeof(struct gl_program_parameter));
+ calloc(size, sizeof(struct gl_program_parameter));
p->ParameterValues = (gl_constant_value (*)[4])
_mesa_align_malloc(size * 4 *sizeof(gl_constant_value), 16);
if (primcount == 0)
return;
- prim = calloc(1, primcount * sizeof(*prim));
+ prim = calloc(primcount, sizeof(*prim));
if (prim == NULL) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements");
return;