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;
|
tf->amount += amount;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tf = (transfer *)malloc(sizeof(transfer));
|
tf = malloc(sizeof(transfer));
|
||||||
if (!tf) abort();
|
if (!tf) abort();
|
||||||
memcpy(tf, &tr, sizeof(transfer));
|
memcpy(tf, &tr, sizeof(transfer));
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,13 +119,13 @@ static void scramble(void *data, unsigned int n, size_t width)
|
||||||
assert(width <= sizeof(temp));
|
assert(width <= sizeof(temp));
|
||||||
for (j = 0; j != n; ++j) {
|
for (j = 0; j != n; ++j) {
|
||||||
unsigned int k = rng_uint() % n;
|
unsigned int k = rng_uint() % n;
|
||||||
if (k == j)
|
if (k != j) {
|
||||||
continue;
|
|
||||||
memcpy(temp, (char*)data + j * width, width);
|
memcpy(temp, (char*)data + j * width, width);
|
||||||
memcpy((char*)data + j * width, (char*)data + k * width, width);
|
memcpy((char*)data + j * width, (char*)data + k * width, width);
|
||||||
memcpy((char*)data + k * width, temp, width);
|
memcpy((char*)data + k * width, temp, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int expand_production(region * r, econ_request * requests, econ_request ***results)
|
int expand_production(region * r, econ_request * requests, econ_request ***results)
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,7 +105,6 @@ const XML_Char *attr_get(const XML_Char **attr, const char *key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static building_stage *stage;
|
static building_stage *stage;
|
||||||
|
|
||||||
#define UPKEEP_MAX 4
|
#define UPKEEP_MAX 4
|
||||||
static maintenance upkeep[UPKEEP_MAX];
|
static maintenance upkeep[UPKEEP_MAX];
|
||||||
static int nupkeep;
|
static int nupkeep;
|
||||||
|
@ -1502,15 +1501,17 @@ static void end_buildings(parseinfo *pi, const XML_Char *el) {
|
||||||
else if (xml_strequal(el, "building")) {
|
else if (xml_strequal(el, "building")) {
|
||||||
stage_ptr = NULL;
|
stage_ptr = NULL;
|
||||||
if (nupkeep > 0) {
|
if (nupkeep > 0) {
|
||||||
btype->maintenance = (maintenance *)calloc(nupkeep + 1, sizeof(maintenance));
|
btype->maintenance = malloc((nupkeep + 1) * sizeof(maintenance));
|
||||||
if (!btype->maintenance) abort();
|
if (!btype->maintenance) abort();
|
||||||
memcpy(btype->maintenance, upkeep, sizeof(maintenance) * nupkeep);
|
memcpy(btype->maintenance, upkeep, sizeof(maintenance) * nupkeep);
|
||||||
|
memset(btype->maintenance + nupkeep, 0, sizeof(maintenance));
|
||||||
nupkeep = 0;
|
nupkeep = 0;
|
||||||
}
|
}
|
||||||
if (nrmods > 0) {
|
if (nrmods > 0) {
|
||||||
btype->modifiers = calloc(nrmods + 1, sizeof(resource_mod));
|
btype->modifiers = malloc((nrmods + 1) * sizeof(resource_mod));
|
||||||
if (!btype->modifiers) abort();
|
if (!btype->modifiers) abort();
|
||||||
memcpy(btype->modifiers, rmods, sizeof(resource_mod) * nrmods);
|
memcpy(btype->modifiers, rmods, sizeof(resource_mod) * nrmods);
|
||||||
|
memset(btype->modifiers + nrmods, 0, sizeof(resource_mod));
|
||||||
nrmods = 0;
|
nrmods = 0;
|
||||||
}
|
}
|
||||||
pi->object = NULL;
|
pi->object = NULL;
|
||||||
|
|
|
@ -51,7 +51,7 @@ syntaxtree *stree_create(void)
|
||||||
syntaxtree *sroot = NULL;
|
syntaxtree *sroot = NULL;
|
||||||
const struct locale *lang = locales;
|
const struct locale *lang = locales;
|
||||||
while (lang) {
|
while (lang) {
|
||||||
syntaxtree *stree = (syntaxtree *)malloc(sizeof(syntaxtree));
|
syntaxtree *stree = malloc(sizeof(syntaxtree));
|
||||||
if (!stree) abort();
|
if (!stree) abort();
|
||||||
stree->lang = lang;
|
stree->lang = lang;
|
||||||
stree->next = sroot;
|
stree->next = sroot;
|
||||||
|
@ -64,7 +64,7 @@ syntaxtree *stree_create(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void stree_add(struct syntaxtree *stree, const char *str, parser fun) {
|
void stree_add(struct syntaxtree *stree, const char *str, parser fun) {
|
||||||
command *cmd = (command *)malloc(sizeof(command));
|
command *cmd = malloc(sizeof(command));
|
||||||
variant var;
|
variant var;
|
||||||
|
|
||||||
assert(str);
|
assert(str);
|
||||||
|
|
|
@ -220,7 +220,7 @@ void free_order(order * ord)
|
||||||
order *copy_order(const order * src)
|
order *copy_order(const order * src)
|
||||||
{
|
{
|
||||||
if (src != NULL) {
|
if (src != NULL) {
|
||||||
order *ord = (order *)malloc(sizeof(order));
|
order *ord = malloc(sizeof(order));
|
||||||
if (!ord) abort();
|
if (!ord) abort();
|
||||||
ord->next = NULL;
|
ord->next = NULL;
|
||||||
ord->command = src->command;
|
ord->command = src->command;
|
||||||
|
@ -335,7 +335,7 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
||||||
else {
|
else {
|
||||||
zBuffer[0] = 0;
|
zBuffer[0] = 0;
|
||||||
}
|
}
|
||||||
ord = (order *)malloc(sizeof(order));
|
ord = malloc(sizeof(order));
|
||||||
create_order_i(ord, kwd, zBuffer, false, false, lang);
|
create_order_i(ord, kwd, zBuffer, false, false, lang);
|
||||||
return ord;
|
return ord;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ order *parse_order(const char *s, const struct locale * lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (kwd != NOKEYWORD) {
|
if (kwd != NOKEYWORD) {
|
||||||
order *ord = (order *)malloc(sizeof(order));
|
order *ord = malloc(sizeof(order));
|
||||||
if (ord == NULL) abort();
|
if (ord == NULL) abort();
|
||||||
create_order_i(ord, kwd, sptr, persistent, noerror, lang);
|
create_order_i(ord, kwd, sptr, persistent, noerror, lang);
|
||||||
return ord;
|
return ord;
|
||||||
|
|
|
@ -226,7 +226,7 @@ race_list *get_familiarraces(void)
|
||||||
|
|
||||||
void racelist_insert(struct race_list **rl, const struct race *r)
|
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();
|
if (!rl2) abort();
|
||||||
rl2->data = r;
|
rl2->data = r;
|
||||||
|
|
Loading…
Reference in a new issue