forked from github/server
code style: do not cast the result of malloc
This commit is contained in:
parent
b9a20bb378
commit
c8d8eb85d3
6 changed files with 16 additions and 15 deletions
|
@ -48,7 +48,7 @@ void add_donation(faction * f1, faction * f2, int amount, region * r)
|
|||
tf->amount += amount;
|
||||
}
|
||||
else {
|
||||
tf = (transfer *)malloc(sizeof(transfer));
|
||||
tf = malloc(sizeof(transfer));
|
||||
if (!tf) abort();
|
||||
memcpy(tf, &tr, sizeof(transfer));
|
||||
}
|
||||
|
|
|
@ -119,11 +119,11 @@ static void scramble(void *data, unsigned int n, size_t width)
|
|||
assert(width <= sizeof(temp));
|
||||
for (j = 0; j != n; ++j) {
|
||||
unsigned int k = rng_uint() % n;
|
||||
if (k == j)
|
||||
continue;
|
||||
memcpy(temp, (char *)data + j * width, width);
|
||||
memcpy((char *)data + j * width, (char *)data + k * width, width);
|
||||
memcpy((char *)data + k * width, temp, width);
|
||||
if (k != j) {
|
||||
memcpy(temp, (char*)data + j * width, width);
|
||||
memcpy((char*)data + j * width, (char*)data + k * width, width);
|
||||
memcpy((char*)data + k * width, temp, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@ const XML_Char *attr_get(const XML_Char **attr, const char *key) {
|
|||
}
|
||||
|
||||
static building_stage *stage;
|
||||
|
||||
#define UPKEEP_MAX 4
|
||||
static maintenance upkeep[UPKEEP_MAX];
|
||||
static int nupkeep;
|
||||
|
@ -1502,15 +1501,17 @@ static void end_buildings(parseinfo *pi, const XML_Char *el) {
|
|||
else if (xml_strequal(el, "building")) {
|
||||
stage_ptr = NULL;
|
||||
if (nupkeep > 0) {
|
||||
btype->maintenance = (maintenance *)calloc(nupkeep + 1, sizeof(maintenance));
|
||||
btype->maintenance = malloc((nupkeep + 1) * sizeof(maintenance));
|
||||
if (!btype->maintenance) abort();
|
||||
memcpy(btype->maintenance, upkeep, sizeof(maintenance) * nupkeep);
|
||||
memset(btype->maintenance + nupkeep, 0, sizeof(maintenance));
|
||||
nupkeep = 0;
|
||||
}
|
||||
if (nrmods > 0) {
|
||||
btype->modifiers = calloc(nrmods + 1, sizeof(resource_mod));
|
||||
btype->modifiers = malloc((nrmods + 1) * sizeof(resource_mod));
|
||||
if (!btype->modifiers) abort();
|
||||
memcpy(btype->modifiers, rmods, sizeof(resource_mod) * nrmods);
|
||||
memset(btype->modifiers + nrmods, 0, sizeof(resource_mod));
|
||||
nrmods = 0;
|
||||
}
|
||||
pi->object = NULL;
|
||||
|
|
|
@ -51,7 +51,7 @@ syntaxtree *stree_create(void)
|
|||
syntaxtree *sroot = NULL;
|
||||
const struct locale *lang = locales;
|
||||
while (lang) {
|
||||
syntaxtree *stree = (syntaxtree *)malloc(sizeof(syntaxtree));
|
||||
syntaxtree *stree = malloc(sizeof(syntaxtree));
|
||||
if (!stree) abort();
|
||||
stree->lang = lang;
|
||||
stree->next = sroot;
|
||||
|
@ -64,7 +64,7 @@ syntaxtree *stree_create(void)
|
|||
}
|
||||
|
||||
void stree_add(struct syntaxtree *stree, const char *str, parser fun) {
|
||||
command *cmd = (command *)malloc(sizeof(command));
|
||||
command *cmd = malloc(sizeof(command));
|
||||
variant var;
|
||||
|
||||
assert(str);
|
||||
|
|
|
@ -220,7 +220,7 @@ void free_order(order * ord)
|
|||
order *copy_order(const order * src)
|
||||
{
|
||||
if (src != NULL) {
|
||||
order *ord = (order *)malloc(sizeof(order));
|
||||
order *ord = malloc(sizeof(order));
|
||||
if (!ord) abort();
|
||||
ord->next = NULL;
|
||||
ord->command = src->command;
|
||||
|
@ -335,7 +335,7 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
|||
else {
|
||||
zBuffer[0] = 0;
|
||||
}
|
||||
ord = (order *)malloc(sizeof(order));
|
||||
ord = malloc(sizeof(order));
|
||||
create_order_i(ord, kwd, zBuffer, false, false, lang);
|
||||
return ord;
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ order *parse_order(const char *s, const struct locale * lang)
|
|||
}
|
||||
}
|
||||
if (kwd != NOKEYWORD) {
|
||||
order *ord = (order *)malloc(sizeof(order));
|
||||
order *ord = malloc(sizeof(order));
|
||||
if (ord == NULL) abort();
|
||||
create_order_i(ord, kwd, sptr, persistent, noerror, lang);
|
||||
return ord;
|
||||
|
|
|
@ -226,7 +226,7 @@ race_list *get_familiarraces(void)
|
|||
|
||||
void racelist_insert(struct race_list **rl, const struct race *r)
|
||||
{
|
||||
race_list *rl2 = (race_list *)malloc(sizeof(race_list));
|
||||
race_list *rl2 = malloc(sizeof(race_list));
|
||||
|
||||
if (!rl2) abort();
|
||||
rl2->data = r;
|
||||
|
|
Loading…
Reference in a new issue