Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all aCalloc calls that had their parameters in the wrong order #3280

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/char/int_party.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ static int inter_party_sql_init(void)
{
//memory alloc
inter_party->db = idb_alloc(DB_OPT_RELEASE_DATA);
inter_party->pt = (struct party_data*)aCalloc(sizeof(struct party_data), 1);
inter_party->pt = (struct party_data*)aCalloc(1, sizeof(struct party_data));
if (!inter_party->pt) {
ShowFatalError("inter_party->sql_init: Out of Memory!\n");
exit(EXIT_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion src/char/int_pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static int inter_pet_fromsql(int pet_id, struct s_pet *p)
static int inter_pet_sql_init(void)
{
//memory alloc
inter_pet->pt = (struct s_pet*)aCalloc(sizeof(struct s_pet), 1);
inter_pet->pt = (struct s_pet*)aCalloc(1, sizeof(struct s_pet));
return 0;
}

Expand Down
14 changes: 7 additions & 7 deletions src/common/memmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
// Enable memory manager logging by default
#define LOG_MEMMGR

#define aMalloc(n) (malloc_proxy((n), ALC_MARK))
#define aCalloc(m, n) (calloc_proxy((m), (n),ALC_MARK))
#define aFree(p) (free_proxy((p), ALC_MARK))
#define aStrdup(p) (strdup_proxy((p),ALC_MARK))
#define aStrndup(p,n) (strndup_proxy((p),(n),ALC_MARK))
#define aRealloc(p,n) (iMalloc->realloc((p),(n),ALC_MARK))
#define aReallocz(p,n) (iMalloc->reallocz((p),(n),ALC_MARK))
#define aMalloc(size) (malloc_proxy((size), ALC_MARK))
#define aCalloc(num, size) (calloc_proxy((num), (size), ALC_MARK))
#define aFree(p) (free_proxy((p), ALC_MARK))
#define aStrdup(p) (strdup_proxy((p), ALC_MARK))
#define aStrndup(p, size) (strndup_proxy((p), (size), ALC_MARK))
#define aRealloc(p, size) (iMalloc->realloc((p), (size), ALC_MARK))
#define aReallocz(p, size) (iMalloc->reallocz((p), (size), ALC_MARK))

/////////////// Buffer Creation /////////////////
// Full credit for this goes to Shinomori [Ajarn]
Expand Down
8 changes: 4 additions & 4 deletions src/map/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ static int instance_add_map(const char *name, int instance_id, bool usebasename,
}

size = map->list[im].bxs * map->list[im].bys * sizeof(struct block_list*);
map->list[im].block = (struct block_list**)aCalloc(size, 1);
map->list[im].block_mob = (struct block_list**)aCalloc(size, 1);
map->list[im].block = (struct block_list**)aCalloc(1, size);
map->list[im].block_mob = (struct block_list**)aCalloc(1, size);

memset(map->list[im].npc, 0x00, sizeof(map->list[i].npc));
map->list[im].npc_num = 0;
Expand Down Expand Up @@ -670,15 +670,15 @@ static void instance_check_idle(int instance_id)
timer->delete(instance->list[instance_id].idle_timer, instance->destroy_timer);
instance->list[instance_id].idle_timer = INVALID_TIMER;
instance->list[instance_id].idle_timeout = 0;

// Notify instance users normal instance expiration
clif->instance(instance_id, INSTANCE_WND_INFO_PROGRESS_TIME, 0);
} else if (instance->list[instance_id].idle_timer == INVALID_TIMER && idle) {
unsigned int now = (unsigned int) time(NULL);
int64 destroy_tick = timer->gettick() + instance->list[instance_id].idle_timeoutval * 1000;
instance->list[instance_id].idle_timeout = now + instance->list[instance_id].idle_timeoutval;
instance->list[instance_id].idle_timer = timer->add(destroy_tick, instance->destroy_timer, instance_id, 0);

// Notify instance users it will be destroyed if no user join it again in "X" time
clif->instance(instance_id, INSTANCE_WND_INFO_IDLE_TIME, 0);
}
Expand Down
8 changes: 4 additions & 4 deletions src/map/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -4031,8 +4031,8 @@ static int map_readallmaps(void)
map->list[i].bys = (map->list[i].ys + BLOCK_SIZE - 1) / BLOCK_SIZE;

size = map->list[i].bxs * map->list[i].bys * sizeof(struct block_list*);
map->list[i].block = (struct block_list**)aCalloc(size, 1);
map->list[i].block_mob = (struct block_list**)aCalloc(size, 1);
map->list[i].block = (struct block_list**)aCalloc(1, size);
map->list[i].block_mob = (struct block_list**)aCalloc(1, size);

map->list[i].getcellp = map->sub_getcellp;
map->list[i].setcell = map->sub_setcell;
Expand Down Expand Up @@ -4585,7 +4585,7 @@ static bool inter_config_read_database_names(const char *filename, const struct

/**
* Looks up configuration "name" which is expect to have a final value of int, but may be specified by a string constant.
*
*
* If the config is a string, it will be looked up using script->get_constant function to find the actual integer value.
*
* @param[in] setting The setting to read.
Expand Down Expand Up @@ -4616,7 +4616,7 @@ static bool map_setting_lookup_const(const struct config_setting_t *setting, con
/**
* Looks up configuration "name" which is expect to have a final value of int,
* but may be specified by a string constant or an array of bitflag constants.
*
*
* If the config is a string, it will be looked up using script->get_constant function to find the actual integer value.
* If the config is an array, each value will be read and added to the final bitmask.
*
Expand Down
4 changes: 2 additions & 2 deletions src/map/mob.c
Original file line number Diff line number Diff line change
Expand Up @@ -4377,7 +4377,7 @@ static bool mob_read_optdrops_optslot(struct config_setting_t *optslot, int n, i
}

struct optdrop_group_optslot *entry = &(mob->opt_drop_groups[group_id].optslot[n]);
entry->options = aCalloc(sizeof(struct optdrop_group_option), count);
entry->options = aCalloc(count, sizeof(struct optdrop_group_option));

int idx = 0;
int i = 0;
Expand Down Expand Up @@ -4458,7 +4458,7 @@ static bool mob_read_optdrops_db(void)
int i = 0;
if (its != NULL && (groups = libconfig->setting_get_elem(its, 0)) != NULL) {
int count = libconfig->setting_length(groups);
mob->opt_drop_groups = aCalloc(sizeof(struct optdrop_group), count);
mob->opt_drop_groups = aCalloc(count, sizeof(struct optdrop_group));
mob->opt_drop_groups_count = count; // maximum size (used by assertions)

struct config_setting_t *group = NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/map/npc_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static struct pcrematch_set *lookup_pcreset(struct npc_data *nd, int setid)
nullpo_retr(NULL, nd);
npcParse = nd->chatdb;
if (npcParse == NULL)
nd->chatdb = npcParse = (struct npc_parse *)aCalloc(sizeof(struct npc_parse), 1);
nd->chatdb = npcParse = (struct npc_parse *) aCalloc(1, sizeof(struct npc_parse));

pcreset = npcParse->active;

Expand All @@ -137,7 +137,7 @@ static struct pcrematch_set *lookup_pcreset(struct npc_data *nd, int setid)
}

if (pcreset == NULL) {
pcreset = (struct pcrematch_set *)aCalloc(sizeof(struct pcrematch_set), 1);
pcreset = (struct pcrematch_set *) aCalloc(1, sizeof(struct pcrematch_set));
pcreset->next = npcParse->inactive;
if (pcreset->next != NULL)
pcreset->next->prev = pcreset;
Expand Down Expand Up @@ -284,7 +284,7 @@ static struct pcrematch_entry *create_pcrematch_entry(struct pcrematch_set *set)
struct pcrematch_entry *last;

nullpo_retr(NULL, set);
e = (struct pcrematch_entry *)aCalloc(sizeof(struct pcrematch_entry), 1);
e = (struct pcrematch_entry *) aCalloc(1, sizeof(struct pcrematch_entry));
last = set->head;

// Normally we would have just stuck it at the end of the list but
Expand Down
8 changes: 4 additions & 4 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -7050,7 +7050,7 @@ static BUILDIN(callfunc)
return false;
}

ref = (struct reg_db *)aCalloc(sizeof(struct reg_db), 2);
ref = (struct reg_db *)aCalloc(2, sizeof(struct reg_db));
ref[0].vars = st->stack->scope.vars;
if (!st->stack->scope.arrays)
st->stack->scope.arrays = idb_alloc(DB_OPT_BASE); // TODO: Can this happen? when?
Expand Down Expand Up @@ -7145,7 +7145,7 @@ static BUILDIN(callfunctionofnpc) {
}

// alloc a reg_db reference of the current scope for the new scope
struct reg_db *ref = (struct reg_db *)aCalloc(sizeof(struct reg_db), 2);
struct reg_db *ref = (struct reg_db *)aCalloc(2, sizeof(struct reg_db));
// scope variables (.@var)
ref[0].vars = st->stack->scope.vars;
ref[0].arrays = st->stack->scope.arrays;
Expand Down Expand Up @@ -7214,7 +7214,7 @@ static BUILDIN(callsub)
return false;
}

ref = (struct reg_db *)aCalloc(sizeof(struct reg_db), 1);
ref = (struct reg_db *) aCalloc(1, sizeof(struct reg_db));
ref[0].vars = st->stack->scope.vars;
if (!st->stack->scope.arrays)
st->stack->scope.arrays = idb_alloc(DB_OPT_BASE); // TODO: Can this happen? when?
Expand Down Expand Up @@ -7312,7 +7312,7 @@ static BUILDIN(return)
// npc variable
if( !data->ref ) {
// npc variable without a reference set, link to current script
data->ref = (struct reg_db *)aCalloc(sizeof(struct reg_db), 1);
data->ref = (struct reg_db *) aCalloc(1, sizeof(struct reg_db));
script->add_pending_ref(st, data->ref);
data->ref->vars = st->script->local.vars;
if( !st->script->local.arrays )
Expand Down
2 changes: 1 addition & 1 deletion src/map/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ static void storage_storage_quit(struct map_session_data *sd, int flag)
static struct DBData create_guildstorage(union DBKey key, va_list args)
{
struct guild_storage *gs = NULL;
gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1);
gs = (struct guild_storage *) aCalloc(1, sizeof(struct guild_storage));
gs->guild_id=key.i;
return DB->ptr2data(gs);
}
Expand Down
Loading