Changeset - r5609:a56ae00a9125
[Not reviewed]
src/ai/ai.cpp
Show inline comments
 
@@ -51,11 +51,11 @@ static void AI_PutCommandInQueue(PlayerI
 

	
 
	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<AICommand>(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<AICommand>(1);
 
		_ai_player[player].queue_tail = _ai_player[player].queue_tail->next;
 
	}
 

	
src/ai/default/default.cpp
Show inline comments
 
@@ -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->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<byte>(GetMaxStationIndex() + 1);
 
	memset(in_use, 0, GetMaxStationIndex() + 1);
 
	FOR_ALL_ORDERS(ord) {
 
		if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1;
src/airport.cpp
Show inline comments
 
@@ -50,7 +50,7 @@ static void AirportPrintOut(const Airpor
 
void InitializeAirports(void)
 
{
 
	// country airport
 
	MallocT(&CountryAirport, 1);
 
	CountryAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		CountryAirport,
 
@@ -65,7 +65,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// city airport
 
	MallocT(&CityAirport, 1);
 
	CityAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		CityAirport,
 
@@ -80,7 +80,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// metropolitan airport
 
	MallocT(&MetropolitanAirport, 1);
 
	MetropolitanAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		MetropolitanAirport,
 
@@ -95,7 +95,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// international airport
 
	MallocT(&InternationalAirport, 1);
 
	InternationalAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		InternationalAirport,
 
@@ -110,7 +110,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// intercontintental airport
 
	MallocT(&IntercontinentalAirport, 1);
 
	IntercontinentalAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		IntercontinentalAirport,
 
@@ -125,7 +125,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// heliport, oilrig
 
	MallocT(&Heliport, 1);
 
	Heliport = MallocT<AirportFTAClass>(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<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		CommuterAirport,
 
@@ -157,7 +157,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// helidepot airport
 
	MallocT(&HeliDepot, 1);
 
	HeliDepot = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		HeliDepot,
 
@@ -172,7 +172,7 @@ void InitializeAirports(void)
 
	);
 

	
 
	// helistation airport
 
	MallocT(&HeliStation, 1);
 
	HeliStation = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		HeliStation,
 
@@ -324,8 +324,7 @@ static byte AirportGetTerminalCount(cons
 
static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup *apFA)
 
{
 
	AirportFTA *current;
 
	AirportFTA *FAutomata;
 
	MallocT(&FAutomata, apc->nofelements);
 
	AirportFTA *FAutomata = MallocT<AirportFTA>(apc->nofelements);
 
	uint16 internalcounter = 0;
 
	uint16 i;
 

	
 
@@ -339,8 +338,7 @@ static void AirportBuildAutomata(Airport
 

	
 
		// outgoing nodes from the same position, create linked list
 
		while (current->position == apFA[internalcounter + 1].position) {
 
			AirportFTA *newNode;
 
			MallocT(&newNode, 1);
 
			AirportFTA *newNode = MallocT<AirportFTA>(1);
 

	
 
			newNode->position      = apFA[internalcounter + 1].position;
 
			newNode->heading       = apFA[internalcounter + 1].heading;
src/aystar.cpp
Show inline comments
 
@@ -36,8 +36,7 @@ static PathNode* AyStarMain_ClosedList_I
 
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<PathNode>(1);
 
	*new_node = *node;
 
	Hash_Set(&aystar->ClosedListHash, node->node.tile, node->node.direction, new_node);
 
}
 
@@ -68,8 +67,7 @@ static OpenListNode *AyStarMain_OpenList
 
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<OpenListNode>(1);
 
	new_node->g = g;
 
	new_node->path.parent = parent;
 
	new_node->path.node = *node;
src/bmp.cpp
Show inline comments
 
@@ -329,7 +329,7 @@ bool BmpReadHeader(BmpBuffer *buffer, Bm
 
		}
 
		if (info->palette_size == 0) info->palette_size = 1 << info->bpp;
 

	
 
		CallocT(&data->palette, info->palette_size);
 
		data->palette = CallocT<Colour>(info->palette_size);
 
		if (data->palette == NULL) return false;
 

	
 
		for (i = 0; i < info->palette_size; i++) {
src/console.cpp
Show inline comments
 
@@ -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<char>(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
 
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc)
 
{
 
	char *new_cmd = strdup(name);
 
	IConsoleCmd *item_new;
 
	MallocT(&item_new, 1);
 
	IConsoleCmd *item_new = MallocT<IConsoleCmd>(1);
 

	
 
	item_new->next = NULL;
 
	item_new->proc = proc;
 
@@ -651,8 +650,7 @@ void IConsoleAliasRegister(const char *n
 
{
 
	char *new_alias = strdup(name);
 
	char *cmd_aliased = strdup(cmd);
 
	IConsoleAlias *item_new;
 
	MallocT(&item_new, 1);
 
	IConsoleAlias *item_new = MallocT<IConsoleAlias>(1);
 

	
 
	item_new->next = NULL;
 
	item_new->cmdline = cmd_aliased;
 
@@ -787,8 +785,7 @@ void IConsoleVarStringRegister(const cha
 
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<IConsoleVar>(1);
 

	
 
	item_new->help = (help != NULL) ? strdup(help) : NULL;
 

	
src/fios.cpp
Show inline comments
 
@@ -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<char>(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<char>(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<char>(MAX_PATH);
 
		strcpy(_fios_hmap_path, _paths.heightmap_dir);
 
	}
 

	
src/fontcache.cpp
Show inline comments
 
@@ -78,7 +78,7 @@ static FT_Error GetFontByFaceName(const 
 
	 * normal char to match the data returned by RegEnumValue,
 
	 * otherwise just use parameter */
 
#if defined(UNICODE)
 
	MallocT(&font_namep, MAX_PATH);
 
	font_namep = MallocT<char>(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, W
 
{
 
	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<GlyphEntry*>(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<GlyphEntry>(256);
 
	}
 

	
 
	DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size);
 
@@ -484,8 +484,8 @@ SpriteID GetUnicodeGlyph(FontSize size, 
 

	
 
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<SpriteID*>(256);
 
	if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = CallocT<SpriteID>(256);
 
	_unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
 
}
 

	
src/graph_gui.cpp
Show inline comments
 
@@ -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;
src/heightmap.cpp
Show inline comments
 
@@ -136,7 +136,7 @@ static bool ReadHeightmapPNG(char *filen
 
	}
 

	
 
	if (map != NULL) {
 
		MallocT(/* NO & */map, info_ptr->width * info_ptr->height);
 
		*map = MallocT<byte>(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 *filen
 
			return false;
 
		}
 

	
 
		MallocT(/* NO & */map, info.width * info.height);
 
		*map = MallocT<byte>(info.width * info.height);
 
		if (*map == NULL) {
 
			ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_BMPMAP_ERROR, 0, 0);
 
			fclose(f);
src/helpers.hpp
Show inline comments
 
@@ -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 <typename T> FORCEINLINE bool MallocT(T** t_ptr, size_t num_elements)
 
template <typename T> 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 <typename T> FORCEINLINE bool CallocT(T** t_ptr, size_t num_elements)
 
template <typename T> 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 <typename T> FORCEINLINE bool ReallocT(T** t_ptr, size_t num_elements)
 
template <typename T> 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 */
src/industry_gui.cpp
Show inline comments
 
@@ -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;
src/map.cpp
Show inline comments
 
@@ -42,7 +42,7 @@ void AllocateMap(uint size_x, uint size_
 
	_map_tile_mask = _map_size - 1;
 

	
 
	free(_m);
 
	CallocT(&_m, _map_size);
 
	_m = CallocT<Tile>(_map_size);
 

	
 
	// XXX TODO handle memory shortage more gracefully
 
	if (_m == NULL) error("Failed to allocate memory for the map");
src/network/core/packet.cpp
Show inline comments
 
@@ -26,8 +26,7 @@ extern void NORETURN CDECL error(const c
 
 */
 
Packet *NetworkSend_Init(const PacketType type)
 
{
 
	Packet *packet;
 
	MallocT(&packet, 1);
 
	Packet *packet = MallocT<Packet>(1);
 
	/* An error is inplace here, because it simply means we ran out of memory. */
 
	if (packet == NULL) error("Failed to allocate Packet");
 

	
src/network/core/tcp.cpp
Show inline comments
 
@@ -149,7 +149,7 @@ Packet *NetworkRecv_Packet(NetworkClient
 
	if (cs->socket == INVALID_SOCKET) return NULL;
 

	
 
	if (cs->packet_recv == NULL) {
 
		MallocT(&cs->packet_recv, 1);
 
		cs->packet_recv = MallocT<Packet>(1);
 
		if (cs->packet_recv == NULL) error("Failed to allocate packet");
 
		/* Set pos to zero! */
 
		cs->packet_recv->pos = 0;
src/network/core/udp.cpp
Show inline comments
 
@@ -252,12 +252,12 @@ void NetworkRecv_NetworkGameInfo(Network
 

	
 
	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<GRFConfig>(1);
 
				NetworkRecv_GRFIdentifier(cs, p, c);
 
				HandleIncomingNetworkGameInfoGRFConfig(c);
 

	
src/network/network_client.cpp
Show inline comments
 
@@ -570,8 +570,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
 
{
 
	CommandPacket *cp;
 
	MallocT(&cp, 1);
 
	CommandPacket *cp = MallocT<CommandPacket>(1);
 
	cp->player = (PlayerID)NetworkRecv_uint8(MY_CLIENT, p);
 
	cp->cmd = NetworkRecv_uint32(MY_CLIENT, p);
 
	cp->p1 = NetworkRecv_uint32(MY_CLIENT, p);
src/network/network_data.cpp
Show inline comments
 
@@ -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<CommandPacket>(1);
 

	
 
	*new_cp = *cp;
 

	
 
@@ -31,8 +30,7 @@ void NetworkAddCommandQueue(NetworkClien
 
// 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<CommandPacket>(1);
 
	byte temp_callback;
 

	
 
	c->player = _local_player;
src/network/network_gamelist.cpp
Show inline comments
 
@@ -26,7 +26,7 @@ NetworkGameList *NetworkGameListAddItem(
 
		prev_item = item;
 
	}
 

	
 
	MallocT(&item, 1);
 
	item = MallocT<NetworkGameList>(1);
 
	memset(item, 0, sizeof(*item));
 
	item->next = NULL;
 
	item->ip = ip;
src/network/network_gui.cpp
Show inline comments
 
@@ -167,7 +167,7 @@ static void BuildNetworkGameList(network
 

	
 
	/* Create temporary array of games to use for listing */
 
	free(nqld->sort_list);
 
	MallocT(&nqld->sort_list, n);
 
	nqld->sort_list = MallocT<NetworkGameList*>(n);
 
	if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list");
 
	nqld->l.list_length = n;
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -793,8 +793,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	const NetworkClientInfo *ci;
 
	byte callback;
 

	
 
	CommandPacket *cp;
 
	MallocT(&cp, 1);
 
	CommandPacket *cp = MallocT<CommandPacket>(1);
 

	
 
	// The client was never joined.. so this is impossible, right?
 
	//  Ignore the packet, give the client a warning, and close his connection
src/newgrf.cpp
Show inline comments
 
@@ -843,7 +843,7 @@ static bool StationChangeInfo(uint stid,
 
	}
 

	
 
	/* 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<StationSpec*>(MAX_STATIONS);
 

	
 
	statspec = &_cur_grffile->stations[stid];
 

	
 
@@ -863,7 +863,7 @@ static bool StationChangeInfo(uint stid,
 
				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<StationSpec>(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,
 
				uint t;
 

	
 
				statspec->tiles = grf_load_extended(&buf);
 
				CallocT(&statspec->renderdata, statspec->tiles);
 
				statspec->renderdata = CallocT<DrawTileSprites>(statspec->tiles);
 
				statspec->copied_renderdata = false;
 

	
 
				for (t = 0; t < statspec->tiles; t++) {
 
@@ -892,7 +892,7 @@ static bool StationChangeInfo(uint stid,
 
						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,
 

	
 
					//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,
 

	
 
					//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,
 
					}
 

	
 
					p = 0;
 
					MallocT(&layout, length * number);
 
					layout = MallocT<byte>(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, 
 

	
 
				if (bridge->sprite_table == NULL) {
 
					/* Allocate memory for sprite table pointers and zero out */
 
					CallocT(&bridge->sprite_table, 7);
 
					bridge->sprite_table = CallocT<PalSpriteID*>(7);
 
				}
 

	
 
				for (; numtables-- != 0; tableid++) {
 
@@ -1089,7 +1089,7 @@ static bool BridgeChangeInfo(uint brid, 
 
					}
 

	
 
					if (bridge->sprite_table[tableid] == NULL) {
 
						MallocT(&bridge->sprite_table[tableid], 32);
 
						bridge->sprite_table[tableid] = MallocT<PalSpriteID>(32);
 
					}
 

	
 
					for (sprite = 0; sprite < 32; sprite++)
 
@@ -1596,7 +1596,7 @@ static void NewSpriteGroup(byte *buf, in
 

	
 
	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, in
 
				}
 

	
 
				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, in
 
			} 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<DeterministicSpriteGroupRange>(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, in
 
			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<const SpriteGroup*>(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, in
 

	
 
					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<const SpriteGroup*>(num_loaded);
 
					if (num_loading > 0) group->g.real.loading = CallocT<const SpriteGroup*>(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 *
 
	}
 

	
 
	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<byte>(num);
 
		FioReadBlock(_preload_sprite, num);
 
	}
 

	
 
@@ -3027,7 +3027,7 @@ static void DefineGotoLabel(byte *buf, i
 
	if (!check_length(len, 1, "DefineGotoLabel")) return;
 
	buf++; len--;
 

	
 
	MallocT(&label, 1);
 
	label = MallocT<GRFLabel>(1);
 
	label->label    = grf_load_byte(&buf);
 
	label->nfo_line = _nfo_line;
 
	label->pos      = FioGetPos();
 
@@ -3490,7 +3490,7 @@ static void InitNewGRFFile(const GRFConf
 
		return;
 
	}
 

	
 
	CallocT(&newfile, 1);
 
	newfile = CallocT<GRFFile>(1);
 

	
 
	if (newfile == NULL) error ("Out of memory");
 

	
 
@@ -3618,7 +3618,7 @@ static void DecodeSpecialSprite(uint num
 
	if (_preload_sprite == NULL) {
 
		/* No preloaded sprite to work with; allocate and read the
 
		 * pseudo sprite content. */
 
		MallocT(&buf, num);
 
		buf = MallocT<byte>(num);
 
		if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
 
		FioReadBlock(buf, num);
 
	} else {
src/newgrf_config.cpp
Show inline comments
 
@@ -119,12 +119,10 @@ void ClearGRFConfigList(GRFConfig **conf
 
 * @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<GRFConfig>(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<GRFConfig>(1);
 
			c->filename = strdup(file);
 

	
 
			if (FillGRFDetails(c, false)) {
 
@@ -375,7 +372,7 @@ char *FindUnknownGRFName(uint32 grfid, u
 

	
 
	if (!create) return NULL;
 

	
 
	CallocT(&grf, 1);
 
	grf = CallocT<UnknownGRF>(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<GRFConfig>(1);
 
		SlObject(c, _grfconfig_desc);
 

	
 
		/* Append our configuration to the list */
src/newgrf_engine.cpp
Show inline comments
 
@@ -83,7 +83,7 @@ void SetWagonOverrideSprites(EngineID en
 

	
 
	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 en
 
	wo->group = group;
 
	wo->cargo = cargo;
 
	wo->trains = trains;
 
	MallocT(&wo->train_id, trains);
 
	wo->train_id = MallocT<byte>(trains);
 
	memcpy(wo->train_id, train_id, trains);
 
}
 

	
src/newgrf_gui.cpp
Show inline comments
 
@@ -154,7 +154,7 @@ static void NewGRFAddDlgWndProc(Window *
 
				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 *
 
						}
 

	
 
						/* Copy GRF details from scanned list */
 
						CallocT(&c, 1);
 
						GRFConfig *c = CallocT<GRFConfig>(1);
 
						*c = *src;
 
						c->filename = strdup(src->filename);
 
						if (src->name != NULL) c->name = strdup(src->name);
src/newgrf_station.cpp
Show inline comments
 
@@ -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<StationSpec*>(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<StationSpec*>(1);
 
	station_classes[1].spec[0] = NULL;
 
}
 

	
 
@@ -148,7 +148,7 @@ void SetCustomStationSpec(StationSpec *s
 
	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 StationS
 
	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* 
 
		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;
src/newgrf_text.cpp
Show inline comments
 
@@ -158,8 +158,7 @@ static byte _currentLangID = GRFLX_ENGLI
 

	
 
char *TranslateTTDPatchCodes(const char *str)
 
{
 
	char *tmp;
 
	MallocT(&tmp, strlen(str) * 10 + 1); /* Allocate space to allow for expansion */
 
	char *tmp = MallocT<char>(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 
 
	}
 

	
 
	*d = '\0';
 
	ReallocT(&tmp, strlen(tmp) + 1);
 
	tmp = ReallocT(tmp, strlen(tmp) + 1);
 
	return tmp;
 
}
 

	
src/oldpool.cpp
Show inline comments
 
@@ -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<byte>(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);
 

	
src/openttd.cpp
Show inline comments
 
@@ -120,7 +120,7 @@ void *ReadFileToMem(const char *filename
 
	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<byte>(len + 1)) == NULL) {
 
		fclose(in);
 
		return NULL;
 
	}
src/queue.cpp
Show inline comments
 
@@ -49,15 +49,14 @@ static Queue* init_stack(Queue* q, uint 
 
	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<void*>(max_size);
 
	q->freeq = false;
 
	return q;
 
}
 

	
 
Queue* new_Stack(uint max_size)
 
{
 
	Queue* q;
 
	MallocT(&q, 1);
 
	Queue* q = MallocT<Queue>(1);
 

	
 
	init_stack(q, max_size);
 
	q->freeq = true;
 
@@ -127,16 +126,14 @@ static Queue* init_fifo(Queue* q, uint m
 
	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<void*>(max_size);
 
	q->freeq = false;
 
	return q;
 
}
 

	
 
Queue* new_Fifo(uint max_size)
 
{
 
	Queue* q;
 
	MallocT(&q, 1);
 

	
 
	Queue* q = MallocT<Queue>(1);
 
	init_fifo(q, max_size);
 
	q->freeq = true;
 
	return q;
 
@@ -169,8 +166,7 @@ static void InsSort_Free(Queue* q, bool 
 

	
 
static bool InsSort_Push(Queue* q, void* item, int priority)
 
{
 
	InsSortNode* newnode;
 
	MallocT(&newnode, 1);
 
	InsSortNode* newnode = MallocT<InsSortNode>(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<Queue>(1);
 

	
 
	init_InsSort(q);
 
	q->freeq = true;
 
@@ -304,7 +299,7 @@ static bool BinaryHeap_Push(Queue* q, vo
 
	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<BinaryHeapNode>(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_
 
	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<BinaryHeapNode*>((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
 
	q->data.binaryheap.elements[0] = MallocT<BinaryHeapNode>(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_
 

	
 
Queue* new_BinaryHeap(uint max_size)
 
{
 
	Queue* q;
 
	MallocT(&q, 1);
 
	Queue* q = MallocT<Queue>(1);
 

	
 
	init_BinaryHeap(q, max_size);
 
	q->freeq = true;
 
@@ -481,8 +475,7 @@ void init_Hash(Hash* h, Hash_HashProc* h
 

	
 
Hash* new_Hash(Hash_HashProc* hash, int num_buckets)
 
{
 
	Hash* h;
 
	MallocT(&h, 1);
 
	Hash* h = MallocT<Hash>(1);
 

	
 
	init_Hash(h, hash, num_buckets);
 
	h->freeh = true;
 
@@ -716,7 +709,7 @@ void* Hash_Set(Hash* h, uint key1, uint 
 
		node = h->buckets + hash;
 
	} else {
 
		/* Add it after prev */
 
		MallocT(&node, 1);
 
		node = MallocT<HashNode>(1);
 
		prev->next = node;
 
	}
 
	node->next = NULL;
src/screenshot.cpp
Show inline comments
 
@@ -68,7 +68,6 @@ static bool MakeBmpImage(const char *nam
 
	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 *nam
 
	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<Pixel>(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_st
 
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 *nam
 
	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<Pixel>(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 *nam
 
	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<Pixel>(w * maxlines); // by default generate 128 lines at a time.
 
	if (buff == NULL) {
 
		fclose(f);
 
		return false;
src/settings.cpp
Show inline comments
 
@@ -236,7 +236,7 @@ static IniFile *ini_load(const char *fil
 
			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 
 
	if (group == NULL) return NULL;
 

	
 
	for (item = group->item; item != NULL; item = item->next) {
 
		GRFConfig *c;
 
		CallocT(&c, 1);
 
		GRFConfig *c = CallocT<GRFConfig>(1);
 
		c->filename = strdup(item->name);
 

	
 
		/* Parse parameters */
src/settings_gui.cpp
Show inline comments
 
@@ -695,7 +695,7 @@ static void PatchesSelectionWndProc(Wind
 
			for (page = &_patches_page[0]; page != endof(_patches_page); page++) {
 
				uint i;
 

	
 
				MallocT(&page->entries, page->num);
 
				page->entries = MallocT<PatchEntry>(page->num);
 
				for (i = 0; i != page->num; i++) {
 
					uint index;
 
					const SettingDesc *sd = GetPatchFromName(page->names[i], &index);
src/sound.cpp
Show inline comments
 
@@ -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<FileEntry>(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 *
 

	
 
	if (fe->file_size == 0) return false;
 

	
 
	MallocT(&mem, fe->file_size);
 
	int8 *mem = MallocT<int8>(fe->file_size);
 
	if (mem == NULL) return false;
 

	
 
	FioSeekToFile(fe->file_offset);
src/sound/win32_s.cpp
Show inline comments
 
@@ -18,7 +18,7 @@ static void PrepareHeader(WAVEHDR *hdr)
 
{
 
	hdr->dwBufferLength = _bufsize * 4;
 
	hdr->dwFlags = 0;
 
	MallocT(&hdr->lpData, _bufsize * 4);
 
	hdr->lpData = MallocT<char>(_bufsize * 4);
 
	if (hdr->lpData == NULL ||
 
			waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
 
		error("waveOutPrepareHeader failed");
src/spritecache.cpp
Show inline comments
 
@@ -38,7 +38,7 @@ static SpriteCache *AllocateSpriteCache(
 

	
 
		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));
src/station_cmd.cpp
Show inline comments
 
@@ -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<StationSpecList>(st->num_specs);
 
		for (i = 0; i < st->num_specs; i++) SlObject(&st->speclist[i], _station_speclist_desc);
 
	}
 
}
src/station_gui.cpp
Show inline comments
 
@@ -198,13 +198,12 @@ static void BuildStationsList(plstations
 
{
 
	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<const Station*>(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
 
	}
 

	
 
	free((void*)sl->sort_list);
 
	MallocT(&sl->sort_list, n);
 
	sl->sort_list = MallocT<const Station*>(n);
 
	if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list");
 
	sl->list_length = n;
 

	
src/strgen/strgen.cpp
Show inline comments
 
@@ -845,7 +845,7 @@ static void HandleString(char *str, bool
 
			}
 

	
 
			// Allocate a new LangString
 
			CallocT(&ent, 1);
 
			ent = CallocT<LangString>(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
 
		}
 

	
 
		if (casep != NULL) {
 
			Case* c;
 
			MallocT(&c, 1);
 
			Case* c = MallocT<Case>(1);
 

	
 
			c->caseidx = ResolveCaseName(casep, strlen(casep));
 
			c->string = strdup(s);
 
@@ -885,8 +884,7 @@ static void HandleString(char *str, bool
 
			if (!CheckCommandsMatch(s, ent->english, str)) return;
 

	
 
			if (casep != NULL) {
 
				Case* c;
 
				MallocT(&c, 1);
 
				Case* c = MallocT<Case>(1);
 

	
 
				c->caseidx = ResolveCaseName(casep, strlen(casep));
 
				c->string = strdup(s);
src/string.cpp
Show inline comments
 
@@ -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<char>(len + 1);
 
	if (p != NULL) memcpy(p, buf, len + 1);
 
	return p;
 
}
src/strings.cpp
Show inline comments
 
@@ -1166,7 +1166,7 @@ bool ReadLanguagePack(int lang_index)
 
	}
 

	
 
	// Allocate offsets
 
	MallocT(&langpack_offs, tot_count);
 
	langpack_offs = MallocT<char*>(tot_count);
 

	
 
	// Fill offsets
 
	s = lang_pack->data;
src/tgp.cpp
Show inline comments
 
@@ -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_t>(_height_map.total_size);
 
	if (_height_map.h == NULL) return false;
 

	
 
	/* Iterate through height map initialize values */
 
@@ -467,12 +467,12 @@ static void HeightMapAdjustWaterLevel(am
 
	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<int>(h_max - h_min + 1);
 
	/* Fill histogram */
 
	hist = HeightMapMakeHistogram(h_min, h_max, hist_buf);
 

	
src/thread.cpp
Show inline comments
 
@@ -31,8 +31,7 @@ static void Proxy(void* arg)
 

	
 
OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg)
 
{
 
	OTTDThread* t;
 
	MallocT(&t, 1);
 
	OTTDThread* t = MallocT<OTTDThread>(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<OTTDThread>(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<OTTDThread>(1);
 
	DWORD dwThreadId;
 

	
 
	if (t == NULL) return NULL;
src/town_gui.cpp
Show inline comments
 
@@ -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;
src/unix.cpp
Show inline comments
 
@@ -169,10 +169,10 @@ void DeterminePaths(void)
 
{
 
	char *s;
 

	
 
	MallocT(&_paths.game_data_dir, MAX_PATH);
 
	_paths.game_data_dir = MallocT<char>(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<char>(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<char>(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<char>(MAX_PATH);
 
	ttd_strlcpy( _paths.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
 
#else
 
	_paths.lang_dir = str_fmt("%slang/", _paths.game_data_dir);
src/vehicle.cpp
Show inline comments
 
@@ -2259,7 +2259,7 @@ static int32 MaybeReplaceVehicle(Vehicle
 
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 Vehic
 
		 * 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<bool>(max + 1);
 
	}
 

	
 
	// Clear the cache
src/vehicle_gui.cpp
Show inline comments
 
@@ -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<RefitOption>(max_lines);
 
	RefitList *list = CallocT<RefitList>(1);
 
	Vehicle *u = (Vehicle*)v;
 
	uint num_lines = 0;
 
	uint i;
src/win32.cpp
Show inline comments
 
@@ -636,7 +636,7 @@ static inline DIR *dir_calloc(void)
 
	DIR *d;
 

	
 
	if (_global_dir_is_in_use) {
 
		CallocT(&d, 1);
 
		d = CallocT<DIR>(1);
 
	} else {
 
		_global_dir_is_in_use = true;
 
		d = &_global_dir;
src/window.cpp
Show inline comments
 
@@ -544,7 +544,7 @@ void AssignWidgetToWindow(Window *w, con
 

	
 
		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 {
0 comments (0 inline, 0 general)