mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Fix a pile of sizeof goofs.
While scan-build wasn't what I was looking for, it has proven useful anyway: many of the sizeof errors were just noise, but a few were actual bugs (allocating too much or too little memory).
This commit is contained in:
parent
575a67b2a1
commit
8fd5be0ee0
15 changed files with 16 additions and 16 deletions
|
@ -102,7 +102,7 @@ filelist_print (filelist_t *filelist)
|
|||
if (filelist->count) {
|
||||
qsort (filelist->list, filelist->count, sizeof (char *), filelist_cmp);
|
||||
|
||||
list = malloc ((filelist->count + 1) * sizeof (char **));
|
||||
list = malloc ((filelist->count + 1) * sizeof (char *));
|
||||
list[filelist->count] = 0;
|
||||
for (i = 0; i < filelist->count; i++)
|
||||
list[i] = filelist->list[i];
|
||||
|
|
|
@ -108,7 +108,7 @@ source_path_f (cvar_t *var)
|
|||
for (i = 2, s = source_path_string; *s; s++)
|
||||
if (*s == ';')
|
||||
i++;
|
||||
source_paths = malloc (i * sizeof (char **));
|
||||
source_paths = malloc (i * sizeof (char *));
|
||||
source_paths[0] = source_path_string;
|
||||
for (i = 1, s = source_path_string; *s; s++)
|
||||
if (*s == ';') {
|
||||
|
|
|
@ -445,7 +445,7 @@ ObjectHash_Get_f (gib_object_t *obj, gib_method_t *method, void *data,
|
|||
if ((refs = (ObjRef_t **) Hash_FindList (objh->objects,
|
||||
mesg.argv[1]))) {
|
||||
for (r = refs, len = 0; *r; r++, len++);
|
||||
reply = malloc (sizeof (char **) * len);
|
||||
reply = malloc (sizeof (char *) * len);
|
||||
for (r = refs, i = 0; *r; r++, i++)
|
||||
reply[i] = (*r)->obj->handstr;
|
||||
GIB_Reply (obj, mesg, len, reply);
|
||||
|
|
|
@ -51,7 +51,7 @@ GIB_Var_New (const char *key)
|
|||
{
|
||||
gib_var_t *new = calloc (1, sizeof (gib_var_t));
|
||||
|
||||
new->array = calloc (1, sizeof (dstring_t *));
|
||||
new->array = calloc (1, sizeof (struct gib_varray_s));
|
||||
new->key = strdup (key);
|
||||
return new;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ sw_iqm_load_textures (iqm_t *iqm)
|
|||
bytes = (iqm->num_verts + 7) / 8;
|
||||
done_verts = alloca (bytes);
|
||||
memset (done_verts, 0, bytes);
|
||||
sw->skins = malloc (iqm->num_meshes * sizeof (tex_t));
|
||||
sw->skins = malloc (iqm->num_meshes * sizeof (tex_t *));
|
||||
for (i = 0; i < iqm->num_meshes; i++) {
|
||||
for (j = 0; j < i; j++) {
|
||||
if (iqm->meshes[j].material == iqm->meshes[i].material) {
|
||||
|
|
|
@ -100,7 +100,7 @@ COM_InitArgv (int argc, const char **argv)
|
|||
safe = false;
|
||||
|
||||
largv = (const char **) calloc (1, (argc + NUM_SAFE_ARGVS + 1) *
|
||||
sizeof (const char **));
|
||||
sizeof (const char *));
|
||||
|
||||
for (com_argc = 0, len = 0; com_argc < argc; com_argc++) {
|
||||
largv[com_argc] = argv[com_argc];
|
||||
|
|
|
@ -161,7 +161,7 @@ read_adtl (dstring_t *list_buf, QFile *f, int len)
|
|||
chunk = &label->ck;
|
||||
break;
|
||||
default:
|
||||
data = malloc (sizeof (data));
|
||||
data = malloc (sizeof (riff_data_t));
|
||||
data->ck = ck;
|
||||
data->data = read_data (f, ck.len);
|
||||
chunk = &data->ck;
|
||||
|
|
|
@ -150,8 +150,8 @@ VID_MakeColormap16 (void *outcolormap, byte *pal)
|
|||
void
|
||||
VID_MakeColormaps (void)
|
||||
{
|
||||
vid.colormap16 = malloc (256*VID_GRADES * sizeof (short));
|
||||
vid.colormap32 = malloc (256*VID_GRADES * sizeof (int));
|
||||
vid.colormap16 = malloc (256*VID_GRADES * sizeof (unsigned short));
|
||||
vid.colormap32 = malloc (256*VID_GRADES * sizeof (unsigned int));
|
||||
SYS_CHECKMEM (vid.colormap16 && vid.colormap32);
|
||||
VID_MakeColormap16(vid.colormap16, vid.palette);
|
||||
VID_MakeColormap32(vid.colormap32, vid.palette);
|
||||
|
|
|
@ -177,7 +177,7 @@ new_tent_object (void)
|
|||
if (!tent_objects) {
|
||||
int i;
|
||||
|
||||
tent_objects = malloc (TEMP_BATCH * sizeof (tent_t));
|
||||
tent_objects = malloc (TEMP_BATCH * sizeof (tent_obj_t));
|
||||
for (i = 0; i < TEMP_BATCH - 1; i++)
|
||||
tent_objects[i].next = &tent_objects[i + 1];
|
||||
tent_objects[i].next = 0;
|
||||
|
|
|
@ -493,7 +493,7 @@ sv_list_f (void)
|
|||
qtv_printf ("no servers\n");
|
||||
return;
|
||||
}
|
||||
list = malloc (count * sizeof (server_t **));
|
||||
list = malloc (count * sizeof (server_t *));
|
||||
for (l = &servers, count = 0; *l; l = &(*l)->next, count++)
|
||||
list[count] = *l;
|
||||
qsort (list, count, sizeof (*list), server_compare);
|
||||
|
|
|
@ -181,7 +181,7 @@ new_tent_object (void)
|
|||
if (!tent_objects) {
|
||||
int i;
|
||||
|
||||
tent_objects = malloc (TEMP_BATCH * sizeof (tent_t));
|
||||
tent_objects = malloc (TEMP_BATCH * sizeof (tent_obj_t));
|
||||
for (i = 0; i < TEMP_BATCH - 1; i++)
|
||||
tent_objects[i].next = &tent_objects[i + 1];
|
||||
tent_objects[i].next = 0;
|
||||
|
|
|
@ -1397,7 +1397,7 @@ add_protocol (protocollist_t *protocollist, const char *name)
|
|||
}
|
||||
protocollist->count++;
|
||||
protocollist->list = realloc (protocollist->list,
|
||||
sizeof (protocol_t) * protocollist->count);
|
||||
sizeof (protocol_t *) * protocollist->count);
|
||||
protocollist->list[protocollist->count - 1] = protocol;
|
||||
return protocollist;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ build_cpp_args (const char *in_name, const char *out_name)
|
|||
|
||||
if (cpp_argv)
|
||||
free (cpp_argv);
|
||||
cpp_argv = (const char **)malloc ((cpp_argc + 1) * sizeof (char**));
|
||||
cpp_argv = (const char **)malloc ((cpp_argc + 1) * sizeof (char *));
|
||||
for (arg = cpp_argv, cpp_arg = cpp_arg_list;
|
||||
cpp_arg;
|
||||
cpp_arg = cpp_arg->next) {
|
||||
|
|
|
@ -343,7 +343,7 @@ flow_build_vars (function_t *func)
|
|||
if (!num_vars)
|
||||
return;
|
||||
|
||||
func->vars = malloc (num_vars * sizeof (daglabel_t *));
|
||||
func->vars = malloc (num_vars * sizeof (flowvar_t *));
|
||||
|
||||
stuse = set_new ();
|
||||
stdef = set_new ();
|
||||
|
|
|
@ -213,7 +213,7 @@ new_case_node (expr_t *low, expr_t *high)
|
|||
if (!is_integer_val (low))
|
||||
internal_error (low, "switch");
|
||||
size = expr_integer (high) - expr_integer (low) + 1;
|
||||
node->labels = calloc (size, sizeof (case_node_t *));
|
||||
node->labels = calloc (size, sizeof (expr_t *));
|
||||
}
|
||||
node->left = node->right = 0;
|
||||
return node;
|
||||
|
|
Loading…
Reference in a new issue