(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
authorKUDr
Thu, 11 Jan 2007 17:29:39 +0000
changeset 5609 dc6a58930ba4
parent 5608 0b0aff054402
child 5610 68b36ebb3469
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
src/ai/ai.cpp
src/ai/default/default.cpp
src/airport.cpp
src/aystar.cpp
src/bmp.cpp
src/console.cpp
src/fios.cpp
src/fontcache.cpp
src/graph_gui.cpp
src/heightmap.cpp
src/helpers.hpp
src/industry_gui.cpp
src/map.cpp
src/network/core/packet.cpp
src/network/core/tcp.cpp
src/network/core/udp.cpp
src/network/network_client.cpp
src/network/network_data.cpp
src/network/network_gamelist.cpp
src/network/network_gui.cpp
src/network/network_server.cpp
src/newgrf.cpp
src/newgrf_config.cpp
src/newgrf_engine.cpp
src/newgrf_gui.cpp
src/newgrf_station.cpp
src/newgrf_text.cpp
src/oldpool.cpp
src/openttd.cpp
src/queue.cpp
src/screenshot.cpp
src/settings.cpp
src/settings_gui.cpp
src/sound.cpp
src/sound/win32_s.cpp
src/spritecache.cpp
src/station_cmd.cpp
src/station_gui.cpp
src/strgen/strgen.cpp
src/string.cpp
src/strings.cpp
src/tgp.cpp
src/thread.cpp
src/town_gui.cpp
src/unix.cpp
src/vehicle.cpp
src/vehicle_gui.cpp
src/win32.cpp
src/window.cpp
--- a/src/ai/ai.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/ai/ai.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -51,11 +51,11 @@
 
 	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;
 	}
 
--- a/src/ai/default/default.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/ai/default/default.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -3575,7 +3575,6 @@
 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 @@
 	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;
--- a/src/airport.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/airport.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -50,7 +50,7 @@
 void InitializeAirports(void)
 {
 	// country airport
-	MallocT(&CountryAirport, 1);
+	CountryAirport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		CountryAirport,
@@ -65,7 +65,7 @@
 	);
 
 	// city airport
-	MallocT(&CityAirport, 1);
+	CityAirport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		CityAirport,
@@ -80,7 +80,7 @@
 	);
 
 	// metropolitan airport
-	MallocT(&MetropolitanAirport, 1);
+	MetropolitanAirport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		MetropolitanAirport,
@@ -95,7 +95,7 @@
 	);
 
 	// international airport
-	MallocT(&InternationalAirport, 1);
+	InternationalAirport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		InternationalAirport,
@@ -110,7 +110,7 @@
 	);
 
 	// intercontintental airport
-	MallocT(&IntercontinentalAirport, 1);
+	IntercontinentalAirport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		IntercontinentalAirport,
@@ -125,7 +125,7 @@
 	);
 
 	// heliport, oilrig
-	MallocT(&Heliport, 1);
+	Heliport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		Heliport,
@@ -142,7 +142,7 @@
 	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 @@
 	);
 
 	// helidepot airport
-	MallocT(&HeliDepot, 1);
+	HeliDepot = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		HeliDepot,
@@ -172,7 +172,7 @@
 	);
 
 	// helistation airport
-	MallocT(&HeliStation, 1);
+	HeliStation = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		HeliStation,
@@ -324,8 +324,7 @@
 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 @@
 
 		// 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;
--- a/src/aystar.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/aystar.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -36,8 +36,7 @@
 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 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;
--- a/src/bmp.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/bmp.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -329,7 +329,7 @@
 		}
 		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++) {
--- a/src/console.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/console.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -224,7 +224,7 @@
 	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 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 @@
 {
 	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 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;
 
--- a/src/fios.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/fios.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -48,7 +48,7 @@
 {
 	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 @@
 	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 @@
 	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 @@
 	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);
 	}
 
--- a/src/fontcache.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/fontcache.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -78,7 +78,7 @@
 	 * 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 @@
 {
 	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 @@
 
 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;
 }
 
--- a/src/graph_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/graph_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -1151,7 +1151,7 @@
 	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;
--- a/src/heightmap.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/heightmap.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -136,7 +136,7 @@
 	}
 
 	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 @@
 			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);
--- a/src/helpers.hpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/helpers.hpp	Thu Jan 11 17:29:39 2007 +0000
@@ -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 */
--- a/src/industry_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/industry_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -560,7 +560,7 @@
 	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;
--- a/src/map.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/map.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -42,7 +42,7 @@
 	_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");
--- a/src/network/core/packet.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/core/packet.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -26,8 +26,7 @@
  */
 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");
 
--- a/src/network/core/tcp.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/core/tcp.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -149,7 +149,7 @@
 	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;
--- a/src/network/core/udp.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/core/udp.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -252,12 +252,12 @@
 
 	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);
 
--- a/src/network/network_client.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/network_client.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -570,8 +570,7 @@
 
 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);
--- a/src/network/network_data.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/network_data.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -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 @@
 // 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;
--- a/src/network/network_gamelist.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/network_gamelist.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -26,7 +26,7 @@
 		prev_item = item;
 	}
 
-	MallocT(&item, 1);
+	item = MallocT<NetworkGameList>(1);
 	memset(item, 0, sizeof(*item));
 	item->next = NULL;
 	item->ip = ip;
--- a/src/network/network_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/network_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -167,7 +167,7 @@
 
 	/* 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;
 
--- a/src/network/network_server.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/network/network_server.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -793,8 +793,7 @@
 	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
--- a/src/newgrf.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/newgrf.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -843,7 +843,7 @@
 	}
 
 	/* 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 @@
 				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 @@
 				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 @@
 						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 @@
 
 					//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 @@
 
 					//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 @@
 					}
 
 					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 @@
 
 				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 @@
 					}
 
 					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 @@
 
 	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 @@
 				}
 
 				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 @@
 			} 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 @@
 			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 @@
 
 					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 @@
 	}
 
 	if (!wagover && last_engines_count != idcount) {
-		ReallocT(&last_engines, idcount);
+		last_engines = ReallocT(last_engines, idcount);
 		last_engines_count = idcount;
 	}
 
@@ -2275,7 +2275,7 @@
 
 	/* 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 @@
 	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 @@
 		return;
 	}
 
-	CallocT(&newfile, 1);
+	newfile = CallocT<GRFFile>(1);
 
 	if (newfile == NULL) error ("Out of memory");
 
@@ -3618,7 +3618,7 @@
 	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 {
--- a/src/newgrf_config.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/newgrf_config.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -119,12 +119,10 @@
  * @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 @@
 	struct stat sb;
 	struct dirent *dirent;
 	DIR *dir;
-	GRFConfig *c;
 
 	if ((dir = opendir(path)) == NULL) return 0;
 
@@ -270,7 +267,7 @@
 			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 @@
 
 	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 @@
 	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 */
--- a/src/newgrf_engine.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/newgrf_engine.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -83,7 +83,7 @@
 
 	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 @@
 	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);
 }
 
--- a/src/newgrf_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/newgrf_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -154,7 +154,7 @@
 				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 @@
 						}
 
 						/* 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);
--- a/src/newgrf_station.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/newgrf_station.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -45,13 +45,13 @@
 	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 @@
 	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 @@
 	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 @@
 		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;
--- a/src/newgrf_text.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/newgrf_text.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -158,8 +158,7 @@
 
 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 @@
 	}
 
 	*d = '\0';
-	ReallocT(&tmp, strlen(tmp) + 1);
+	tmp = ReallocT(tmp, strlen(tmp) + 1);
 	return tmp;
 }
 
--- a/src/oldpool.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/oldpool.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -50,11 +50,11 @@
 	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);
 
--- a/src/openttd.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/openttd.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -120,7 +120,7 @@
 	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;
 	}
--- a/src/queue.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/queue.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -49,15 +49,14 @@
 	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 @@
 	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 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 @@
 
 Queue* new_InsSort(void)
 {
-	Queue* q;
-	MallocT(&q, 1);
+	Queue* q = MallocT<Queue>(1);
 
 	init_InsSort(q);
 	q->freeq = true;
@@ -304,7 +299,7 @@
 	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 @@
 	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 @@
 
 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 @@
 
 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 @@
 		node = h->buckets + hash;
 	} else {
 		/* Add it after prev */
-		MallocT(&node, 1);
+		node = MallocT<HashNode>(1);
 		prev->next = node;
 	}
 	node->next = NULL;
--- a/src/screenshot.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/screenshot.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -68,7 +68,6 @@
 	BitmapFileHeader bfh;
 	BitmapInfoHeader bih;
 	RgbQuad rq[256];
-	Pixel *buff;
 	FILE *f;
 	uint i, padw;
 	uint n, maxlines;
@@ -119,7 +118,7 @@
 	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 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 @@
 	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 @@
 
 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 @@
 	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;
--- a/src/settings.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/settings.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -236,7 +236,7 @@
 			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 @@
 	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 */
--- a/src/settings_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/settings_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -695,7 +695,7 @@
 			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);
--- a/src/sound.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/sound.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -23,13 +23,12 @@
 
 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 @@
 static bool SetBankSource(MixerChannel *mc, uint bank)
 {
 	const FileEntry *fe;
-	int8 *mem;
 	uint i;
 
 	if (bank >= GetNumSounds()) return false;
@@ -110,7 +108,7 @@
 
 	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);
--- a/src/sound/win32_s.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/sound/win32_s.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -18,7 +18,7 @@
 {
 	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");
--- a/src/spritecache.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/spritecache.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -38,7 +38,7 @@
 
 		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));
--- a/src/station_cmd.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/station_cmd.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -3065,7 +3065,7 @@
 
 	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);
 	}
 }
--- a/src/station_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/station_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -198,13 +198,12 @@
 {
 	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 @@
 	}
 
 	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;
 
--- a/src/strgen/strgen.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/strgen/strgen.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -845,7 +845,7 @@
 			}
 
 			// 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 @@
 		}
 
 		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 @@
 			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);
--- a/src/string.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/string.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -59,12 +59,11 @@
 	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;
 }
--- a/src/strings.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/strings.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -1166,7 +1166,7 @@
 	}
 
 	// Allocate offsets
-	MallocT(&langpack_offs, tot_count);
+	langpack_offs = MallocT<char*>(tot_count);
 
 	// Fill offsets
 	s = lang_pack->data;
--- a/src/tgp.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/tgp.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -239,7 +239,7 @@
 	/* 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 @@
 	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);
 
--- a/src/thread.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/thread.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -31,8 +31,7 @@
 
 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 @@
 
 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 @@
 
 OTTDThread* OTTDCreateThread(OTTDThreadFunc function, void* arg)
 {
-	OTTDThread* t;
-	MallocT(&t, 1);
+	OTTDThread* t = MallocT<OTTDThread>(1);
 	DWORD dwThreadId;
 
 	if (t == NULL) return NULL;
--- a/src/town_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/town_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -410,7 +410,7 @@
 	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;
--- a/src/unix.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/unix.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -169,10 +169,10 @@
 {
 	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 @@
 
 #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 @@
 
 #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);
--- a/src/vehicle.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/vehicle.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -2259,7 +2259,7 @@
 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 @@
 		 * 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 @@
 	if (max > gmax) {
 		gmax = max;
 		free(cache);
-		MallocT(&cache, max + 1);
+		cache = MallocT<bool>(max + 1);
 	}
 
 	// Clear the cache
--- a/src/vehicle_gui.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/vehicle_gui.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -207,10 +207,8 @@
 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;
--- a/src/win32.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/win32.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -636,7 +636,7 @@
 	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;
--- a/src/window.cpp	Thu Jan 11 15:30:35 2007 +0000
+++ b/src/window.cpp	Thu Jan 11 17:29:39 2007 +0000
@@ -544,7 +544,7 @@
 
 		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 {