diff --git a/src/donations.c b/src/donations.c index eee9e6fda..f092b3409 100644 --- a/src/donations.c +++ b/src/donations.c @@ -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)); } diff --git a/src/economy.c b/src/economy.c index 016d09ff8..fff2f76b0 100644 --- a/src/economy.c +++ b/src/economy.c @@ -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); + } } } diff --git a/src/exparse.c b/src/exparse.c index 791223c61..0e66aa8ae 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -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; diff --git a/src/kernel/command.c b/src/kernel/command.c index bf547e2d4..02530f55a 100644 --- a/src/kernel/command.c +++ b/src/kernel/command.c @@ -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); diff --git a/src/kernel/order.c b/src/kernel/order.c index 7352f8ccc..401352ad5 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -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; diff --git a/src/kernel/race.c b/src/kernel/race.c index 850a42259..bd02e6cd9 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -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;