diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index 5b2e5a8fc8..3921fd873d 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -51,11 +51,11 @@ static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uin if (_ai_player[player].queue_tail == NULL) { /* There is no item in the queue yet, create the queue */ - MallocT(&_ai_player[player].queue, 1); + _ai_player[player].queue = MallocT(1); _ai_player[player].queue_tail = _ai_player[player].queue; } else { /* Add an item at the end */ - MallocT(&_ai_player[player].queue_tail->next, 1); + _ai_player[player].queue_tail->next = MallocT(1); _ai_player[player].queue_tail = _ai_player[player].queue_tail->next; } diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index fff5cef8a8..09e2f68a4b 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -3575,7 +3575,6 @@ return_to_loop:; static void AiStateRemoveStation(Player *p) { // Remove stations that aren't in use by any vehicle - byte *in_use; const Order *ord; const Station *st; TileIndex tile; @@ -3584,7 +3583,7 @@ static void AiStateRemoveStation(Player *p) p->ai.state = AIS_1; // Get a list of all stations that are in use by a vehicle - MallocT(&in_use, GetMaxStationIndex() + 1); + byte *in_use = MallocT(GetMaxStationIndex() + 1); memset(in_use, 0, GetMaxStationIndex() + 1); FOR_ALL_ORDERS(ord) { if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1; diff --git a/src/airport.cpp b/src/airport.cpp index 60df231bb3..0c1370a72c 100644 --- a/src/airport.cpp +++ b/src/airport.cpp @@ -50,7 +50,7 @@ static void AirportPrintOut(const AirportFTAClass *apc, bool full_report); void InitializeAirports(void) { // country airport - MallocT(&CountryAirport, 1); + CountryAirport = MallocT(1); AirportFTAClass_Constructor( CountryAirport, @@ -65,7 +65,7 @@ void InitializeAirports(void) ); // city airport - MallocT(&CityAirport, 1); + CityAirport = MallocT(1); AirportFTAClass_Constructor( CityAirport, @@ -80,7 +80,7 @@ void InitializeAirports(void) ); // metropolitan airport - MallocT(&MetropolitanAirport, 1); + MetropolitanAirport = MallocT(1); AirportFTAClass_Constructor( MetropolitanAirport, @@ -95,7 +95,7 @@ void InitializeAirports(void) ); // international airport - MallocT(&InternationalAirport, 1); + InternationalAirport = MallocT(1); AirportFTAClass_Constructor( InternationalAirport, @@ -110,7 +110,7 @@ void InitializeAirports(void) ); // intercontintental airport - MallocT(&IntercontinentalAirport, 1); + IntercontinentalAirport = MallocT(1); AirportFTAClass_Constructor( IntercontinentalAirport, @@ -125,7 +125,7 @@ void InitializeAirports(void) ); // heliport, oilrig - MallocT(&Heliport, 1); + Heliport = MallocT(1); AirportFTAClass_Constructor( Heliport, @@ -142,7 +142,7 @@ void InitializeAirports(void) Oilrig = Heliport; // exactly the same structure for heliport/oilrig, so share state machine // commuter airport - MallocT(&CommuterAirport, 1); + CommuterAirport = MallocT(1); AirportFTAClass_Constructor( CommuterAirport, @@ -157,7 +157,7 @@ void InitializeAirports(void) ); // helidepot airport - MallocT(&HeliDepot, 1); + HeliDepot = MallocT(1); AirportFTAClass_Constructor( HeliDepot, @@ -172,7 +172,7 @@ void InitializeAirports(void) ); // helistation airport - MallocT(&HeliStation, 1); + HeliStation = MallocT(1); AirportFTAClass_Constructor( HeliStation, @@ -324,8 +324,7 @@ static byte AirportGetTerminalCount(const byte *terminals, byte *groups) static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup *apFA) { AirportFTA *current; - AirportFTA *FAutomata; - MallocT(&FAutomata, apc->nofelements); + AirportFTA *FAutomata = MallocT(apc->nofelements); uint16 internalcounter = 0; uint16 i; @@ -339,8 +338,7 @@ static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup * // outgoing nodes from the same position, create linked list while (current->position == apFA[internalcounter + 1].position) { - AirportFTA *newNode; - MallocT(&newNode, 1); + AirportFTA *newNode = MallocT(1); newNode->position = apFA[internalcounter + 1].position; newNode->heading = apFA[internalcounter + 1].heading; diff --git a/src/aystar.cpp b/src/aystar.cpp index 36260d4f36..8c7e608519 100644 --- a/src/aystar.cpp +++ b/src/aystar.cpp @@ -36,8 +36,7 @@ static PathNode* AyStarMain_ClosedList_IsInList(AyStar *aystar, const AyStarNode static void AyStarMain_ClosedList_Add(AyStar *aystar, const PathNode *node) { // Add a node to the ClosedList - PathNode *new_node; - MallocT(&new_node, 1); + PathNode *new_node = MallocT(1); *new_node = *node; Hash_Set(&aystar->ClosedListHash, node->node.tile, node->node.direction, new_node); } @@ -68,8 +67,7 @@ static OpenListNode *AyStarMain_OpenList_Pop(AyStar *aystar) static void AyStarMain_OpenList_Add(AyStar *aystar, PathNode *parent, const AyStarNode *node, int f, int g) { // Add a new Node to the OpenList - OpenListNode *new_node; - MallocT(&new_node, 1); + OpenListNode *new_node = MallocT(1); new_node->g = g; new_node->path.parent = parent; new_node->path.node = *node; diff --git a/src/bmp.cpp b/src/bmp.cpp index e9a882021f..381d95014d 100644 --- a/src/bmp.cpp +++ b/src/bmp.cpp @@ -329,7 +329,7 @@ bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data) } if (info->palette_size == 0) info->palette_size = 1 << info->bpp; - CallocT(&data->palette, info->palette_size); + data->palette = CallocT(info->palette_size); if (data->palette == NULL) return false; for (i = 0; i < info->palette_size; i++) { diff --git a/src/console.cpp b/src/console.cpp index cf192fb33a..4cb6e8af74 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -224,7 +224,7 @@ void IConsoleInit(void) memset(_iconsole_history, 0, sizeof(_iconsole_history)); memset(_iconsole_buffer, 0, sizeof(_iconsole_buffer)); memset(_iconsole_cbuffer, 0, sizeof(_iconsole_cbuffer)); - CallocT(&_iconsole_cmdline.buf, ICON_CMDLN_SIZE); // create buffer and zero it + _iconsole_cmdline.buf = CallocT(ICON_CMDLN_SIZE); // create buffer and zero it _iconsole_cmdline.maxlength = ICON_CMDLN_SIZE; IConsolePrintF(13, "OpenTTD Game Console Revision 7 - %s", _openttd_revision); @@ -613,8 +613,7 @@ void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook * void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc) { char *new_cmd = strdup(name); - IConsoleCmd *item_new; - MallocT(&item_new, 1); + IConsoleCmd *item_new = MallocT(1); item_new->next = NULL; item_new->proc = proc; @@ -651,8 +650,7 @@ void IConsoleAliasRegister(const char *name, const char *cmd) { char *new_alias = strdup(name); char *cmd_aliased = strdup(cmd); - IConsoleAlias *item_new; - MallocT(&item_new, 1); + IConsoleAlias *item_new = MallocT(1); item_new->next = NULL; item_new->cmdline = cmd_aliased; @@ -787,8 +785,7 @@ void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help) { char *new_cmd = strdup(name); - IConsoleVar *item_new; - MallocT(&item_new, 1); + IConsoleVar *item_new = MallocT(1); item_new->help = (help != NULL) ? strdup(help) : NULL; diff --git a/src/fios.cpp b/src/fios.cpp index 87e7ea93de..a833426a34 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -48,7 +48,7 @@ FiosItem *FiosAlloc(void) { if (_fios_count == _fios_alloc) { _fios_alloc += 256; - ReallocT(&_fios_items, _fios_alloc); + _fios_items = ReallocT(_fios_items, _fios_alloc); } return &_fios_items[_fios_count++]; } @@ -324,7 +324,7 @@ FiosItem *FiosGetSavegameList(int mode) static char *_fios_save_path = NULL; if (_fios_save_path == NULL) { - MallocT(&_fios_save_path, MAX_PATH); + _fios_save_path = MallocT(MAX_PATH); ttd_strlcpy(_fios_save_path, _paths.save_dir, MAX_PATH); } @@ -372,7 +372,7 @@ FiosItem *FiosGetScenarioList(int mode) static char *_fios_scn_path = NULL; if (_fios_scn_path == NULL) { - MallocT(&_fios_scn_path, MAX_PATH); + _fios_scn_path = MallocT(MAX_PATH); ttd_strlcpy(_fios_scn_path, _paths.scenario_dir, MAX_PATH); } @@ -403,7 +403,7 @@ FiosItem *FiosGetHeightmapList(int mode) static char *_fios_hmap_path = NULL; if (_fios_hmap_path == NULL) { - MallocT(&_fios_hmap_path, MAX_PATH); + _fios_hmap_path = MallocT(MAX_PATH); strcpy(_fios_hmap_path, _paths.heightmap_dir); } diff --git a/src/fontcache.cpp b/src/fontcache.cpp index e60fe8bc70..ce0a885d57 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -78,7 +78,7 @@ static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) * normal char to match the data returned by RegEnumValue, * otherwise just use parameter */ #if defined(UNICODE) - MallocT(&font_namep, MAX_PATH); + font_namep = MallocT(MAX_PATH); MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR)); #else font_namep = (char*)font_name; // only cast because in unicode pointer is not const @@ -346,12 +346,12 @@ static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph) { if (_glyph_ptr[size] == NULL) { DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size); - CallocT(&_glyph_ptr[size], 256); + _glyph_ptr[size] = CallocT(256); } if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) { DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size); - CallocT(&_glyph_ptr[size][GB(key, 8, 8)], 256); + _glyph_ptr[size][GB(key, 8, 8)] = CallocT(256); } DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size); @@ -484,8 +484,8 @@ SpriteID GetUnicodeGlyph(FontSize size, uint32 key) void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite) { - if (_unicode_glyph_map[size] == NULL) CallocT(&_unicode_glyph_map[size], 256); - if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) CallocT(&_unicode_glyph_map[size][GB(key, 8, 8)], 256); + if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = CallocT(256); + if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = CallocT(256); _unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite; } diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 3528e71e00..53ebd1fc22 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1151,7 +1151,7 @@ static void GlobalSortSignList(void) uint n = 0; /* Create array for sorting */ - ReallocT(&_sign_sort, GetMaxSignIndex() + 1); + _sign_sort = ReallocT(_sign_sort, GetMaxSignIndex() + 1); if (_sign_sort == NULL) error("Could not allocate memory for the sign-sorting-list"); FOR_ALL_SIGNS(si) _sign_sort[n++] = si; diff --git a/src/heightmap.cpp b/src/heightmap.cpp index 85e5d34a34..adedc06b4d 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -136,7 +136,7 @@ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map) } if (map != NULL) { - MallocT(/* NO & */map, info_ptr->width * info_ptr->height); + *map = MallocT(info_ptr->width * info_ptr->height); if (*map == NULL) { ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_PNGMAP_ERROR, 0, 0); @@ -249,7 +249,7 @@ static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map) return false; } - MallocT(/* NO & */map, info.width * info.height); + *map = MallocT(info.width * info.height); if (*map == NULL) { ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_BMPMAP_ERROR, 0, 0); fclose(f); diff --git a/src/helpers.hpp b/src/helpers.hpp index b13fc25d44..14b6056b35 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -10,24 +10,24 @@ /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value * from void* to the proper pointer type. Another alternative would be MallocT<> as follows */ -template FORCEINLINE bool MallocT(T** t_ptr, size_t num_elements) +template FORCEINLINE T* MallocT(size_t num_elements) { - *t_ptr = (T*)malloc(num_elements * sizeof(T)); - return (*t_ptr != NULL); + T *t_ptr = (T*)malloc(num_elements * sizeof(T)); + return t_ptr; } /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value * from void* to the proper pointer type. Another alternative would be MallocT<> as follows */ -template FORCEINLINE bool CallocT(T** t_ptr, size_t num_elements) +template FORCEINLINE T* CallocT(size_t num_elements) { - *t_ptr = (T*)calloc(num_elements, sizeof(T)); - return (*t_ptr != NULL); + T *t_ptr = (T*)calloc(num_elements, sizeof(T)); + return t_ptr; } /** When allocating using malloc/calloc in C++ it is usually needed to cast the return value * from void* to the proper pointer type. Another alternative would be MallocT<> as follows */ -template FORCEINLINE bool ReallocT(T** t_ptr, size_t num_elements) +template FORCEINLINE T* ReallocT(T* t_ptr, size_t num_elements) { - *t_ptr = (T*)realloc(*t_ptr, num_elements * sizeof(T)); - return (*t_ptr != NULL); + t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T)); + return t_ptr; } /** type safe swap operation */ diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 0fb98bc2ce..2b09178115 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -560,7 +560,7 @@ static void MakeSortedIndustryList(void) if (GetNumIndustries() == 0) return; /* Create array for sorting */ - ReallocT(&_industry_sort, GetMaxIndustryIndex() + 1); + _industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1); if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list"); FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i; diff --git a/src/map.cpp b/src/map.cpp index 05a51d8e82..ca590e92bc 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -42,7 +42,7 @@ void AllocateMap(uint size_x, uint size_y) _map_tile_mask = _map_size - 1; free(_m); - CallocT(&_m, _map_size); + _m = CallocT(_map_size); // XXX TODO handle memory shortage more gracefully if (_m == NULL) error("Failed to allocate memory for the map"); diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index 38d00d8c0c..511e0c675a 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -26,8 +26,7 @@ extern void NORETURN CDECL error(const char *str, ...); */ Packet *NetworkSend_Init(const PacketType type) { - Packet *packet; - MallocT(&packet, 1); + Packet *packet = MallocT(1); /* An error is inplace here, because it simply means we ran out of memory. */ if (packet == NULL) error("Failed to allocate Packet"); diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index ce00335fea..98b5d8d5da 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -149,7 +149,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status) if (cs->socket == INVALID_SOCKET) return NULL; if (cs->packet_recv == NULL) { - MallocT(&cs->packet_recv, 1); + cs->packet_recv = MallocT(1); if (cs->packet_recv == NULL) error("Failed to allocate packet"); /* Set pos to zero! */ cs->packet_recv->pos = 0; diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp index 91d751fd50..0776a2c503 100644 --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -252,12 +252,12 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI switch (info->game_info_version) { case 4: { - GRFConfig *c, **dst = &info->grfconfig; + GRFConfig **dst = &info->grfconfig; uint i; uint num_grfs = NetworkRecv_uint8(cs, p); for (i = 0; i < num_grfs; i++) { - CallocT(&c, 1); + GRFConfig *c = CallocT(1); NetworkRecv_GRFIdentifier(cs, p, c); HandleIncomingNetworkGameInfoGRFConfig(c); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 338d076e6c..9e9b5969c6 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -570,8 +570,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC) DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND) { - CommandPacket *cp; - MallocT(&cp, 1); + CommandPacket *cp = MallocT(1); cp->player = (PlayerID)NetworkRecv_uint8(MY_CLIENT, p); cp->cmd = NetworkRecv_uint32(MY_CLIENT, p); cp->p1 = NetworkRecv_uint32(MY_CLIENT, p); diff --git a/src/network/network_data.cpp b/src/network/network_data.cpp index 89011f18d3..4b0166c9ab 100644 --- a/src/network/network_data.cpp +++ b/src/network/network_data.cpp @@ -14,8 +14,7 @@ // Add a command to the local command queue void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp) { - CommandPacket* new_cp; - MallocT(&new_cp, 1); + CommandPacket* new_cp = MallocT(1); *new_cp = *cp; @@ -31,8 +30,7 @@ void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp) // Prepare a DoCommand to be send over the network void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback) { - CommandPacket *c; - MallocT(&c, 1); + CommandPacket *c = MallocT(1); byte temp_callback; c->player = _local_player; diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp index b1b3993bb1..a202769e0e 100644 --- a/src/network/network_gamelist.cpp +++ b/src/network/network_gamelist.cpp @@ -26,7 +26,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port) prev_item = item; } - MallocT(&item, 1); + item = MallocT(1); memset(item, 0, sizeof(*item)); item->next = NULL; item->ip = ip; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 7a6fc221bd..56fad89ee6 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -167,7 +167,7 @@ static void BuildNetworkGameList(network_ql_d *nqld) /* Create temporary array of games to use for listing */ free(nqld->sort_list); - MallocT(&nqld->sort_list, n); + nqld->sort_list = MallocT(n); if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list"); nqld->l.list_length = n; diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c7bc2069db..ed7951c411 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -793,8 +793,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) const NetworkClientInfo *ci; byte callback; - CommandPacket *cp; - MallocT(&cp, 1); + CommandPacket *cp = MallocT(1); // The client was never joined.. so this is impossible, right? // Ignore the packet, give the client a warning, and close his connection diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 988698762a..6d4f1a333b 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -843,7 +843,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int } /* Allocate station specs if necessary */ - if (_cur_grffile->stations == NULL) CallocT(&_cur_grffile->stations, MAX_STATIONS); + if (_cur_grffile->stations == NULL) _cur_grffile->stations = CallocT(MAX_STATIONS); statspec = &_cur_grffile->stations[stid]; @@ -863,7 +863,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int uint32 classid; /* Property 0x08 is special; it is where the station is allocated */ - if (statspec[i] == NULL) CallocT(&statspec[i], 1); + if (statspec[i] == NULL) statspec[i] = CallocT(1); /* Swap classid because we read it in BE meaning WAYP or DFLT */ classid = grf_load_dword(&buf); @@ -877,7 +877,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int uint t; statspec->tiles = grf_load_extended(&buf); - CallocT(&statspec->renderdata, statspec->tiles); + statspec->renderdata = CallocT(statspec->tiles); statspec->copied_renderdata = false; for (t = 0; t < statspec->tiles; t++) { @@ -892,7 +892,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int DrawTileSeqStruct *dtss; // no relative bounding box support - ReallocT((DrawTileSeqStruct**)&dts->seq, ++seq_count); + dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count); dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1]; dtss->delta_x = grf_load_byte(&buf); @@ -958,10 +958,10 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int //debug("l %d > %d ?", length, stat->lengths); if (length > statspec->lengths) { - ReallocT(&statspec->platforms, length); + statspec->platforms = ReallocT(statspec->platforms, length); memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths); - ReallocT(&statspec->layouts, length); + statspec->layouts = ReallocT(statspec->layouts, length); memset(statspec->layouts + statspec->lengths, 0, (length - statspec->lengths) * sizeof(*statspec->layouts)); @@ -971,7 +971,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int //debug("p %d > %d ?", number, stat->platforms[l]); if (number > statspec->platforms[l]) { - ReallocT(&statspec->layouts[l], number); + statspec->layouts[l] = ReallocT(statspec->layouts[l], number); // We expect NULL being 0 here, but C99 guarantees that. memset(statspec->layouts[l] + statspec->platforms[l], 0, (number - statspec->platforms[l]) * sizeof(**statspec->layouts)); @@ -980,7 +980,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int } p = 0; - MallocT(&layout, length * number); + layout = MallocT(length * number); for (l = 0; l < length; l++) { for (p = 0; p < number; p++) { layout[l * number + p] = grf_load_byte(&buf); @@ -1076,7 +1076,7 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int if (bridge->sprite_table == NULL) { /* Allocate memory for sprite table pointers and zero out */ - CallocT(&bridge->sprite_table, 7); + bridge->sprite_table = CallocT(7); } for (; numtables-- != 0; tableid++) { @@ -1089,7 +1089,7 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int } if (bridge->sprite_table[tableid] == NULL) { - MallocT(&bridge->sprite_table[tableid], 32); + bridge->sprite_table[tableid] = MallocT(32); } for (sprite = 0; sprite < 32; sprite++) @@ -1596,7 +1596,7 @@ static void NewSpriteGroup(byte *buf, int len) if (setid >= _cur_grffile->spritegroups_count) { // Allocate memory for new sprite group references. - ReallocT(&_cur_grffile->spritegroups, setid + 1); + _cur_grffile->spritegroups = ReallocT(_cur_grffile->spritegroups, setid + 1); // Initialise new space to NULL for (; _cur_grffile->spritegroups_count < (setid + 1); _cur_grffile->spritegroups_count++) _cur_grffile->spritegroups[_cur_grffile->spritegroups_count] = NULL; @@ -1641,7 +1641,7 @@ static void NewSpriteGroup(byte *buf, int len) } group->g.determ.num_adjusts++; - ReallocT(&group->g.determ.adjusts, group->g.determ.num_adjusts); + group->g.determ.adjusts = ReallocT(group->g.determ.adjusts, group->g.determ.num_adjusts); adjust = &group->g.determ.adjusts[group->g.determ.num_adjusts - 1]; @@ -1667,7 +1667,7 @@ static void NewSpriteGroup(byte *buf, int len) } while (HASBIT(varadjust, 5)); group->g.determ.num_ranges = grf_load_byte(&buf); - CallocT(&group->g.determ.ranges, group->g.determ.num_ranges); + group->g.determ.ranges = CallocT(group->g.determ.num_ranges); if (!check_length(bufend - buf, 2 + (2 + 2 * varsize) * group->g.determ.num_ranges, "NewSpriteGroup (Deterministic)")) return; @@ -1699,7 +1699,7 @@ static void NewSpriteGroup(byte *buf, int len) group->g.random.cmp_mode = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY; group->g.random.lowest_randbit = grf_load_byte(&buf); group->g.random.num_groups = grf_load_byte(&buf); - CallocT(&group->g.random.groups, group->g.random.num_groups); + group->g.random.groups = CallocT(group->g.random.num_groups); if (!check_length(bufend - buf, 2 * group->g.random.num_groups, "NewSpriteGroup (Randomized) (2)")) return; @@ -1739,8 +1739,8 @@ static void NewSpriteGroup(byte *buf, int len) group->g.real.num_loaded = num_loaded; group->g.real.num_loading = num_loading; - if (num_loaded > 0) CallocT(&group->g.real.loaded, num_loaded); - if (num_loading > 0) CallocT(&group->g.real.loading, num_loading); + if (num_loaded > 0) group->g.real.loaded = CallocT(num_loaded); + if (num_loading > 0) group->g.real.loading = CallocT(num_loading); grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading", setid, sprites, num_loaded, num_loading); @@ -1885,7 +1885,7 @@ static void FeatureMapSpriteGroup(byte *buf, int len) } if (!wagover && last_engines_count != idcount) { - ReallocT(&last_engines, idcount); + last_engines = ReallocT(last_engines, idcount); last_engines_count = idcount; } @@ -2275,7 +2275,7 @@ static void CfgApply(byte *buf, int len) /* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */ if (type == 0xFF) { - MallocT(&_preload_sprite, num); + _preload_sprite = MallocT(num); FioReadBlock(_preload_sprite, num); } @@ -3027,7 +3027,7 @@ static void DefineGotoLabel(byte *buf, int len) if (!check_length(len, 1, "DefineGotoLabel")) return; buf++; len--; - MallocT(&label, 1); + label = MallocT(1); label->label = grf_load_byte(&buf); label->nfo_line = _nfo_line; label->pos = FioGetPos(); @@ -3490,7 +3490,7 @@ static void InitNewGRFFile(const GRFConfig *config, int sprite_offset) return; } - CallocT(&newfile, 1); + newfile = CallocT(1); if (newfile == NULL) error ("Out of memory"); @@ -3618,7 +3618,7 @@ static void DecodeSpecialSprite(uint num, GrfLoadingStage stage) if (_preload_sprite == NULL) { /* No preloaded sprite to work with; allocate and read the * pseudo sprite content. */ - MallocT(&buf, num); + buf = MallocT(num); if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory"); FioReadBlock(buf, num); } else { diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index c624328dd1..1c49bd2075 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -119,12 +119,10 @@ void ClearGRFConfigList(GRFConfig **config) * @return pointer to the last value added to the destination list */ GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src) { - GRFConfig *c; - /* Clear destination as it will be overwritten */ ClearGRFConfigList(dst); for (; src != NULL; src = src->next) { - CallocT(&c, 1); + GRFConfig *c = CallocT(1); *c = *src; if (src->filename != NULL) c->filename = strdup(src->filename); if (src->name != NULL) c->name = strdup(src->name); @@ -245,7 +243,6 @@ static uint ScanPath(const char *path) struct stat sb; struct dirent *dirent; DIR *dir; - GRFConfig *c; if ((dir = opendir(path)) == NULL) return 0; @@ -270,7 +267,7 @@ static uint ScanPath(const char *path) if (ext == NULL) continue; if (strcasecmp(ext, ".grf") != 0) continue; - CallocT(&c, 1); + GRFConfig *c = CallocT(1); c->filename = strdup(file); if (FillGRFDetails(c, false)) { @@ -375,7 +372,7 @@ char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create) if (!create) return NULL; - CallocT(&grf, 1); + grf = CallocT(1); grf->grfid = grfid; grf->next = unknown_grfs; ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name)); @@ -446,8 +443,7 @@ static void Load_NGRF(void) GRFConfig **last = &first; while (SlIterateArray() != -1) { - GRFConfig *c; - CallocT(&c, 1); + GRFConfig *c = CallocT(1); SlObject(c, _grfconfig_desc); /* Append our configuration to the list */ diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 58f1e43b6d..7732c77f15 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -83,7 +83,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup * wos = &_engine_wagon_overrides[engine]; wos->overrides_count++; - ReallocT(&wos->overrides, wos->overrides_count); + wos->overrides = ReallocT(wos->overrides, wos->overrides_count); wo = &wos->overrides[wos->overrides_count - 1]; /* FIXME: If we are replacing an override, release original SpriteGroup @@ -92,7 +92,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup * wo->group = group; wo->cargo = cargo; wo->trains = trains; - MallocT(&wo->train_id, trains); + wo->train_id = MallocT(trains); memcpy(wo->train_id, train_id, trains); } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 7eb63d7226..d5934a4338 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -154,7 +154,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e) case 6: /* Add selection to list */ if (WP(w, newgrf_add_d).sel != NULL) { const GRFConfig *src = WP(w, newgrf_add_d).sel; - GRFConfig **list, *c; + GRFConfig **list; /* Find last entry in the list, checking for duplicate grfid on the way */ for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) { @@ -165,7 +165,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e) } /* Copy GRF details from scanned list */ - CallocT(&c, 1); + GRFConfig *c = CallocT(1); *c = *src; c->filename = strdup(src->filename); if (src->name != NULL) c->name = strdup(src->name); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 0ef1ec84ed..0b910da582 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -45,13 +45,13 @@ void ResetStationClasses(void) station_classes[0].id = 'DFLT'; station_classes[0].name = STR_STAT_CLASS_DFLT; station_classes[0].stations = 1; - MallocT(&station_classes[0].spec, 1); + station_classes[0].spec = MallocT(1); station_classes[0].spec[0] = NULL; station_classes[1].id = 'WAYP'; station_classes[1].name = STR_STAT_CLASS_WAYP; station_classes[1].stations = 1; - MallocT(&station_classes[1].spec, 1); + station_classes[1].spec = MallocT(1); station_classes[1].spec[0] = NULL; } @@ -148,7 +148,7 @@ void SetCustomStationSpec(StationSpec *statspec) station_class = &station_classes[statspec->sclass]; i = station_class->stations++; - ReallocT(&station_class->spec, station_class->stations); + station_class->spec = ReallocT(station_class->spec, station_class->stations); station_class->spec[i] = statspec; statspec->allocated = true; @@ -607,7 +607,7 @@ int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec) if (exec) { if (i >= st->num_specs) { st->num_specs = i + 1; - ReallocT(&st->speclist, st->num_specs); + st->speclist = ReallocT(st->speclist, st->num_specs); if (st->num_specs == 2) { /* Initial allocation */ @@ -653,7 +653,7 @@ void DeallocateSpecFromStation(Station* st, byte specindex) for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--); if (st->num_specs > 1) { - ReallocT(&st->speclist, st->num_specs); + st->speclist = ReallocT(st->speclist, st->num_specs); } else { free(st->speclist); st->num_specs = 0; diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index af1dc688a4..021defb9c0 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -158,8 +158,7 @@ static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used. char *TranslateTTDPatchCodes(const char *str) { - char *tmp; - MallocT(&tmp, strlen(str) * 10 + 1); /* Allocate space to allow for expansion */ + char *tmp = MallocT(strlen(str) * 10 + 1); /* Allocate space to allow for expansion */ char *d = tmp; bool unicode = false; WChar c; @@ -255,7 +254,7 @@ char *TranslateTTDPatchCodes(const char *str) } *d = '\0'; - ReallocT(&tmp, strlen(tmp) + 1); + tmp = ReallocT(tmp, strlen(tmp) + 1); return tmp; } diff --git a/src/oldpool.cpp b/src/oldpool.cpp index d19aa684ee..f226307a11 100644 --- a/src/oldpool.cpp +++ b/src/oldpool.cpp @@ -50,11 +50,11 @@ bool AddBlockToPool(OldMemoryPool *pool) DEBUG(misc, 4, "[Pool] (%s) increasing size of pool to %d items (%d bytes)", pool->name, pool->total_items, pool->total_items * pool->item_size); /* Increase the poolsize */ - ReallocT(&pool->blocks, pool->current_blocks + 1); + pool->blocks = ReallocT(pool->blocks, pool->current_blocks + 1); if (pool->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", pool->name); /* Allocate memory to the new block item */ - MallocT(&pool->blocks[pool->current_blocks], pool->item_size * (1 << pool->block_size_bits)); + pool->blocks[pool->current_blocks] = MallocT(pool->item_size * (1 << pool->block_size_bits)); if (pool->blocks[pool->current_blocks] == NULL) error("Pool: (%s) could not allocate memory for blocks", pool->name); diff --git a/src/openttd.cpp b/src/openttd.cpp index c1a66a555e..92181045ff 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -120,7 +120,7 @@ void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) fseek(in, 0, SEEK_END); len = ftell(in); fseek(in, 0, SEEK_SET); - if (len > maxsize || !MallocT(&mem, len + 1)) { + if (len > maxsize || (mem = MallocT(len + 1)) == NULL) { fclose(in); return NULL; } diff --git a/src/queue.cpp b/src/queue.cpp index 44ace52e5b..b371908e0f 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -49,15 +49,14 @@ static Queue* init_stack(Queue* q, uint max_size) q->free = Stack_Free; q->data.stack.max_size = max_size; q->data.stack.size = 0; - MallocT(&q->data.stack.elements, max_size); + q->data.stack.elements = MallocT(max_size); q->freeq = false; return q; } Queue* new_Stack(uint max_size) { - Queue* q; - MallocT(&q, 1); + Queue* q = MallocT(1); init_stack(q, max_size); q->freeq = true; @@ -127,16 +126,14 @@ static Queue* init_fifo(Queue* q, uint max_size) q->data.fifo.max_size = max_size; q->data.fifo.head = 0; q->data.fifo.tail = 0; - MallocT(&q->data.fifo.elements, max_size); + q->data.fifo.elements = MallocT(max_size); q->freeq = false; return q; } Queue* new_Fifo(uint max_size) { - Queue* q; - MallocT(&q, 1); - + Queue* q = MallocT(1); init_fifo(q, max_size); q->freeq = true; return q; @@ -169,8 +166,7 @@ static void InsSort_Free(Queue* q, bool free_values) static bool InsSort_Push(Queue* q, void* item, int priority) { - InsSortNode* newnode; - MallocT(&newnode, 1); + InsSortNode* newnode = MallocT(1); if (newnode == NULL) return false; newnode->item = item; @@ -224,8 +220,7 @@ void init_InsSort(Queue* q) Queue* new_InsSort(void) { - Queue* q; - MallocT(&q, 1); + Queue* q = MallocT(1); init_InsSort(q); q->freeq = true; @@ -304,7 +299,7 @@ static bool BinaryHeap_Push(Queue* q, void* item, int priority) if (q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] == NULL) { /* The currently allocated blocks are full, allocate a new one */ assert((q->data.binaryheap.size & BINARY_HEAP_BLOCKSIZE_MASK) == 0); - MallocT(&q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS], BINARY_HEAP_BLOCKSIZE); + q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] = MallocT(BINARY_HEAP_BLOCKSIZE); q->data.binaryheap.blocks++; #ifdef QUEUE_DEBUG printf("[BinaryHeap] Increasing size of elements to %d nodes\n", q->data.binaryheap.blocks * BINARY_HEAP_BLOCKSIZE); @@ -432,8 +427,8 @@ void init_BinaryHeap(Queue* q, uint max_size) q->data.binaryheap.size = 0; // We malloc memory in block of BINARY_HEAP_BLOCKSIZE // It autosizes when it runs out of memory - CallocT(&q->data.binaryheap.elements, (max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1); - MallocT(&q->data.binaryheap.elements[0], BINARY_HEAP_BLOCKSIZE); + q->data.binaryheap.elements = CallocT((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1); + q->data.binaryheap.elements[0] = MallocT(BINARY_HEAP_BLOCKSIZE); q->data.binaryheap.blocks = 1; q->freeq = false; #ifdef QUEUE_DEBUG @@ -443,8 +438,7 @@ void init_BinaryHeap(Queue* q, uint max_size) Queue* new_BinaryHeap(uint max_size) { - Queue* q; - MallocT(&q, 1); + Queue* q = MallocT(1); init_BinaryHeap(q, max_size); q->freeq = true; @@ -481,8 +475,7 @@ void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets) Hash* new_Hash(Hash_HashProc* hash, int num_buckets) { - Hash* h; - MallocT(&h, 1); + Hash* h = MallocT(1); init_Hash(h, hash, num_buckets); h->freeh = true; @@ -716,7 +709,7 @@ void* Hash_Set(Hash* h, uint key1, uint key2, void* value) node = h->buckets + hash; } else { /* Add it after prev */ - MallocT(&node, 1); + node = MallocT(1); prev->next = node; } node->next = NULL; diff --git a/src/screenshot.cpp b/src/screenshot.cpp index f66745540a..9408d20f0d 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -68,7 +68,6 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user BitmapFileHeader bfh; BitmapInfoHeader bih; RgbQuad rq[256]; - Pixel *buff; FILE *f; uint i, padw; uint n, maxlines; @@ -119,7 +118,7 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user maxlines = clamp(65536 / padw, 16, 128); // now generate the bitmap bits - MallocT(&buff, padw * maxlines); // by default generate 128 lines at a time. + Pixel *buff = MallocT(padw * maxlines); // by default generate 128 lines at a time. if (buff == NULL) { fclose(f); return false; @@ -170,7 +169,6 @@ static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) { png_color rq[256]; - Pixel *buff; FILE *f; uint i, y, n; uint maxlines; @@ -226,7 +224,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user maxlines = clamp(65536 / w, 16, 128); // now generate the bitmap bits - MallocT(&buff, w * maxlines); // by default generate 128 lines at a time. + Pixel *buff = MallocT(w * maxlines); // by default generate 128 lines at a time. if (buff == NULL) { png_destroy_write_struct(&png_ptr, &info_ptr); fclose(f); @@ -283,7 +281,6 @@ assert_compile(sizeof(PcxHeader) == 128); static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) { - Pixel *buff; FILE *f; uint maxlines; uint y; @@ -323,7 +320,7 @@ static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *user maxlines = clamp(65536 / w, 16, 128); // now generate the bitmap bits - MallocT(&buff, w * maxlines); // by default generate 128 lines at a time. + Pixel *buff = MallocT(w * maxlines); // by default generate 128 lines at a time. if (buff == NULL) { fclose(f); return false; diff --git a/src/settings.cpp b/src/settings.cpp index e6dd5514fe..37b1b83f95 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -236,7 +236,7 @@ static IniFile *ini_load(const char *filename) if (ns > a) { a = max(a, 128U); do a*=2; while (a < ns); - ReallocT(&comment, comment_alloc = a); + comment = ReallocT(comment, comment_alloc = a); } pos = comment_size; comment_size += (e - s + 1); @@ -1509,8 +1509,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati if (group == NULL) return NULL; for (item = group->item; item != NULL; item = item->next) { - GRFConfig *c; - CallocT(&c, 1); + GRFConfig *c = CallocT(1); c->filename = strdup(item->name); /* Parse parameters */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index e3253f4609..9819e845c5 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -695,7 +695,7 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) for (page = &_patches_page[0]; page != endof(_patches_page); page++) { uint i; - MallocT(&page->entries, page->num); + page->entries = MallocT(page->num); for (i = 0; i != page->num; i++) { uint index; const SettingDesc *sd = GetPatchFromName(page->names[i], &index); diff --git a/src/sound.cpp b/src/sound.cpp index c1d9c73f45..1a60b14bae 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -23,13 +23,12 @@ static FileEntry *_files; static void OpenBankFile(const char *filename) { - FileEntry *fe; uint count; uint i; FioOpenFile(SOUND_SLOT, filename); count = FioReadDword() / 8; - CallocT(&fe, count); + FileEntry *fe = CallocT(count); if (fe == NULL) { _file_count = 0; @@ -102,7 +101,6 @@ uint GetNumOriginalSounds(void) static bool SetBankSource(MixerChannel *mc, uint bank) { const FileEntry *fe; - int8 *mem; uint i; if (bank >= GetNumSounds()) return false; @@ -110,7 +108,7 @@ static bool SetBankSource(MixerChannel *mc, uint bank) if (fe->file_size == 0) return false; - MallocT(&mem, fe->file_size); + int8 *mem = MallocT(fe->file_size); if (mem == NULL) return false; FioSeekToFile(fe->file_offset); diff --git a/src/sound/win32_s.cpp b/src/sound/win32_s.cpp index a1ecab017d..68194ad39b 100644 --- a/src/sound/win32_s.cpp +++ b/src/sound/win32_s.cpp @@ -18,7 +18,7 @@ static void PrepareHeader(WAVEHDR *hdr) { hdr->dwBufferLength = _bufsize * 4; hdr->dwFlags = 0; - MallocT(&hdr->lpData, _bufsize * 4); + hdr->lpData = MallocT(_bufsize * 4); if (hdr->lpData == NULL || waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) error("waveOutPrepareHeader failed"); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 6eaa1d7fd0..1f9d838ed3 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -38,7 +38,7 @@ static SpriteCache *AllocateSpriteCache(uint index) DEBUG(sprite, 4, "Increasing sprite cache to %d items (%d bytes)", items, items * sizeof(*_spritecache)); - ReallocT(&_spritecache, items); + _spritecache = ReallocT(_spritecache, items); if (_spritecache == NULL) { error("Unable to allocate sprite cache of %d items (%d bytes)", items, items * sizeof(*_spritecache)); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index e94da91da5..ea89c45f9f 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3065,7 +3065,7 @@ static void SaveLoad_STNS(Station *st) if (st->num_specs != 0) { /* Allocate speclist memory when loading a game */ - if (st->speclist == NULL) CallocT(&st->speclist, st->num_specs); + if (st->speclist == NULL) st->speclist = CallocT(st->num_specs); for (i = 0; i < st->num_specs; i++) SlObject(&st->speclist[i], _station_speclist_desc); } } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index c4f778e1af..94f6d63411 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -198,13 +198,12 @@ static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, { uint n = 0; uint i, j; - const Station** station_sort; const Station *st; if (!(sl->flags & SL_REBUILD)) return; /* Create array for sorting */ - MallocT(&station_sort, GetMaxStationIndex() + 1); + const Station** station_sort = MallocT(GetMaxStationIndex() + 1); if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list"); DEBUG(misc, 3, "Building station list for player %d", owner); @@ -231,7 +230,7 @@ static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, } free((void*)sl->sort_list); - MallocT(&sl->sort_list, n); + sl->sort_list = MallocT(n); if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list"); sl->list_length = n; diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index 4268f0bbbe..9b6ae5102e 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -845,7 +845,7 @@ static void HandleString(char *str, bool master) } // Allocate a new LangString - CallocT(&ent, 1); + ent = CallocT(1); _strings[_next_string_id] = ent; ent->index = _next_string_id++; ent->name = strdup(str); @@ -855,8 +855,7 @@ static void HandleString(char *str, bool master) } if (casep != NULL) { - Case* c; - MallocT(&c, 1); + Case* c = MallocT(1); c->caseidx = ResolveCaseName(casep, strlen(casep)); c->string = strdup(s); @@ -885,8 +884,7 @@ static void HandleString(char *str, bool master) if (!CheckCommandsMatch(s, ent->english, str)) return; if (casep != NULL) { - Case* c; - MallocT(&c, 1); + Case* c = MallocT(1); c->caseidx = ResolveCaseName(casep, strlen(casep)); c->string = strdup(s); diff --git a/src/string.cpp b/src/string.cpp index 7e4aaf1d21..4556ac64b8 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -59,12 +59,11 @@ char* CDECL str_fmt(const char* str, ...) char buf[4096]; va_list va; int len; - char* p; va_start(va, str); len = vsnprintf(buf, lengthof(buf), str, va); va_end(va); - MallocT(&p, len + 1); + char* p = MallocT(len + 1); if (p != NULL) memcpy(p, buf, len + 1); return p; } diff --git a/src/strings.cpp b/src/strings.cpp index 86a6709fc0..6d1f29b9d4 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1166,7 +1166,7 @@ bool ReadLanguagePack(int lang_index) } // Allocate offsets - MallocT(&langpack_offs, tot_count); + langpack_offs = MallocT(tot_count); // Fill offsets s = lang_pack->data; diff --git a/src/tgp.cpp b/src/tgp.cpp index 491562cd3c..88630b9579 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -239,7 +239,7 @@ static inline bool AllocHeightMap(void) /* Allocate memory block for height map row pointers */ _height_map.total_size = (_height_map.size_x + 1) * (_height_map.size_y + 1); _height_map.dim_x = _height_map.size_x + 1; - CallocT(&_height_map.h, _height_map.total_size); + _height_map.h = CallocT(_height_map.total_size); if (_height_map.h == NULL) return false; /* Iterate through height map initialize values */ @@ -467,12 +467,12 @@ static void HeightMapAdjustWaterLevel(amplitude_t water_percent, height_t h_max_ height_t h_min, h_max, h_avg, h_water_level; int water_tiles, desired_water_tiles; height_t *h; - int *hist_buf, *hist; + int *hist; HeightMapGetMinMaxAvg(&h_min, &h_max, &h_avg); /* Allocate histogram buffer and clear its cells */ - CallocT(&hist_buf, h_max - h_min + 1); + int *hist_buf = CallocT(h_max - h_min + 1); /* Fill histogram */ hist = HeightMapMakeHistogram(h_min, h_max, hist_buf); diff --git a/src/thread.cpp b/src/thread.cpp index 233c4ecb63..66456d1ab0 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -31,8 +31,7 @@ static void Proxy(void* arg) OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) { - OTTDThread* t; - MallocT(&t, 1); + OTTDThread* t = MallocT(1); if (t == NULL) return NULL; @@ -74,8 +73,7 @@ struct OTTDThread { OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) { - OTTDThread* t; - MallocT(&t, 1); + OTTDThread* t = MallocT(1); if (t == NULL) return NULL; @@ -123,8 +121,7 @@ static DWORD WINAPI Proxy(LPVOID arg) OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg) { - OTTDThread* t; - MallocT(&t, 1); + OTTDThread* t = MallocT(1); DWORD dwThreadId; if (t == NULL) return NULL; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 56084b3b2f..51894dfd41 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -410,7 +410,7 @@ static void MakeSortedTownList(void) uint n = 0; /* Create array for sorting */ - ReallocT(&_town_sort, GetMaxTownIndex() + 1); + _town_sort = ReallocT(_town_sort, GetMaxTownIndex() + 1); if (_town_sort == NULL) error("Could not allocate memory for the town-sorting-list"); FOR_ALL_TOWNS(t) _town_sort[n++] = t; diff --git a/src/unix.cpp b/src/unix.cpp index ba15b8701a..cd32b76314 100644 --- a/src/unix.cpp +++ b/src/unix.cpp @@ -169,10 +169,10 @@ void DeterminePaths(void) { char *s; - MallocT(&_paths.game_data_dir, MAX_PATH); + _paths.game_data_dir = MallocT(MAX_PATH); ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH); #if defined SECOND_DATA_DIR - MallocT(&_paths.second_data_dir, MAX_PATH); + _paths.second_data_dir = MallocT(MAX_PATH); ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH); #endif @@ -190,7 +190,7 @@ void DeterminePaths(void) #else /* not defined(USE_HOMEDIR) */ - MallocT(&_paths.personal_dir, MAX_PATH); + _paths.personal_dir = MallocT(MAX_PATH); ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH); // check if absolute or relative path @@ -226,7 +226,7 @@ void DeterminePaths(void) #if defined CUSTOM_LANG_DIR // sets the search path for lng files to the custom one - MallocT(&_paths.lang_dir, MAX_PATH ); + _paths.lang_dir = MallocT(MAX_PATH); ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); #else _paths.lang_dir = str_fmt("%slang/", _paths.game_data_dir); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 8a0b475883..6e5b081605 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2259,7 +2259,7 @@ static int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs) static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *engine_list_length, uint16 step_size) { *engine_list_length = min(*engine_list_length + step_size, GetMaxVehicleIndex() + 1); - ReallocT((Vehicle ***)/* NO & */engine_list, *engine_list_length); + *engine_list = ReallocT(*engine_list, *engine_list_length); } /** Generates a list of vehicles inside a depot @@ -2436,7 +2436,7 @@ uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array * We will still make it have room for 50 extra vehicles to prevent having * to move the whole array if just one vehicle is added later */ *length_of_array = n + 50; - ReallocT((Vehicle***)/* NO & */sort_list, (*length_of_array) * sizeof((*sort_list)[0])); + *sort_list = ReallocT(*sort_list, (*length_of_array) * sizeof((*sort_list)[0])); } return n; @@ -2781,7 +2781,7 @@ UnitID GetFreeUnitNumber(byte type) if (max > gmax) { gmax = max; free(cache); - MallocT(&cache, max + 1); + cache = MallocT(max + 1); } // Clear the cache diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 55dd412ecf..7db4ee1c62 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -207,10 +207,8 @@ typedef struct RefitList { static RefitList *BuildRefitList(const Vehicle *v) { uint max_lines = 256; - RefitOption *refit; - CallocT(&refit, max_lines); - RefitList *list; - CallocT(&list, 1); + RefitOption *refit = CallocT(max_lines); + RefitList *list = CallocT(1); Vehicle *u = (Vehicle*)v; uint num_lines = 0; uint i; diff --git a/src/win32.cpp b/src/win32.cpp index 4235814670..b41204a9d8 100644 --- a/src/win32.cpp +++ b/src/win32.cpp @@ -636,7 +636,7 @@ static inline DIR *dir_calloc(void) DIR *d; if (_global_dir_is_in_use) { - CallocT(&d, 1); + d = CallocT(1); } else { _global_dir_is_in_use = true; d = &_global_dir; diff --git a/src/window.cpp b/src/window.cpp index 583876ecf0..7977bed0cb 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -544,7 +544,7 @@ void AssignWidgetToWindow(Window *w, const Widget *widget) for (wi = widget; wi->type != WWT_LAST; wi++) index++; - ReallocT(&w->widget, index); + w->widget = ReallocT(w->widget, index); memcpy(w->widget, widget, sizeof(*w->widget) * index); w->widget_count = index - 1; } else {