(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter

This commit is contained in:
KUDr 2007-01-11 17:29:39 +00:00
parent 91ff746410
commit 33be1ecfb1
49 changed files with 141 additions and 181 deletions

View File

@ -51,11 +51,11 @@ static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uin
if (_ai_player[player].queue_tail == NULL) {
/* There is no item in the queue yet, create the queue */
MallocT(&_ai_player[player].queue, 1);
_ai_player[player].queue = MallocT<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;
}

View File

@ -3575,7 +3575,6 @@ return_to_loop:;
static void AiStateRemoveStation(Player *p)
{
// Remove stations that aren't in use by any vehicle
byte *in_use;
const Order *ord;
const Station *st;
TileIndex tile;
@ -3584,7 +3583,7 @@ static void AiStateRemoveStation(Player *p)
p->ai.state = AIS_1;
// Get a list of all stations that are in use by a vehicle
MallocT(&in_use, GetMaxStationIndex() + 1);
byte *in_use = MallocT<byte>(GetMaxStationIndex() + 1);
memset(in_use, 0, GetMaxStationIndex() + 1);
FOR_ALL_ORDERS(ord) {
if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1;

View File

@ -50,7 +50,7 @@ static void AirportPrintOut(const AirportFTAClass *apc, bool full_report);
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(const byte *terminals, byte *groups)
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(AirportFTAClass *apc, const AirportFTAbuildup *
// outgoing nodes from the same position, create linked list
while (current->position == apFA[internalcounter + 1].position) {
AirportFTA *newNode;
MallocT(&newNode, 1);
AirportFTA *newNode = MallocT<AirportFTA>(1);
newNode->position = apFA[internalcounter + 1].position;
newNode->heading = apFA[internalcounter + 1].heading;

View File

@ -36,8 +36,7 @@ static PathNode* AyStarMain_ClosedList_IsInList(AyStar *aystar, const AyStarNode
static void AyStarMain_ClosedList_Add(AyStar *aystar, const PathNode *node)
{
// Add a node to the ClosedList
PathNode *new_node;
MallocT(&new_node, 1);
PathNode *new_node = MallocT<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_Pop(AyStar *aystar)
static void AyStarMain_OpenList_Add(AyStar *aystar, PathNode *parent, const AyStarNode *node, int f, int g)
{
// Add a new Node to the OpenList
OpenListNode *new_node;
MallocT(&new_node, 1);
OpenListNode *new_node = MallocT<OpenListNode>(1);
new_node->g = g;
new_node->path.parent = parent;
new_node->path.node = *node;

View File

@ -329,7 +329,7 @@ bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
}
if (info->palette_size == 0) info->palette_size = 1 << info->bpp;
CallocT(&data->palette, info->palette_size);
data->palette = CallocT<Colour>(info->palette_size);
if (data->palette == NULL) return false;
for (i = 0; i < info->palette_size; i++) {

View File

@ -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, IConsoleHookTypes type, IConsoleHook *
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc)
{
char *new_cmd = strdup(name);
IConsoleCmd *item_new;
MallocT(&item_new, 1);
IConsoleCmd *item_new = MallocT<IConsoleCmd>(1);
item_new->next = NULL;
item_new->proc = proc;
@ -651,8 +650,7 @@ void IConsoleAliasRegister(const char *name, const char *cmd)
{
char *new_alias = strdup(name);
char *cmd_aliased = strdup(cmd);
IConsoleAlias *item_new;
MallocT(&item_new, 1);
IConsoleAlias *item_new = MallocT<IConsoleAlias>(1);
item_new->next = NULL;
item_new->cmdline = cmd_aliased;
@ -787,8 +785,7 @@ void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const
void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help)
{
char *new_cmd = strdup(name);
IConsoleVar *item_new;
MallocT(&item_new, 1);
IConsoleVar *item_new = MallocT<IConsoleVar>(1);
item_new->help = (help != NULL) ? strdup(help) : NULL;

View File

@ -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);
}

View File

@ -78,7 +78,7 @@ static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
* normal char to match the data returned by RegEnumValue,
* otherwise just use parameter */
#if defined(UNICODE)
MallocT(&font_namep, MAX_PATH);
font_namep = MallocT<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, WChar key, const GlyphEntry *glyph)
{
if (_glyph_ptr[size] == NULL) {
DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size);
CallocT(&_glyph_ptr[size], 256);
_glyph_ptr[size] = CallocT<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, uint32 key)
void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite)
{
if (_unicode_glyph_map[size] == NULL) CallocT(&_unicode_glyph_map[size], 256);
if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) CallocT(&_unicode_glyph_map[size][GB(key, 8, 8)], 256);
if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = CallocT<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;
}

View File

@ -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;

View File

@ -136,7 +136,7 @@ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
}
if (map != NULL) {
MallocT(/* NO & */map, info_ptr->width * info_ptr->height);
*map = MallocT<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 *filename, uint *x, uint *y, byte **map)
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);

View File

@ -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 */

View File

@ -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;

View File

@ -42,7 +42,7 @@ void AllocateMap(uint size_x, uint size_y)
_map_tile_mask = _map_size - 1;
free(_m);
CallocT(&_m, _map_size);
_m = CallocT<Tile>(_map_size);
// XXX TODO handle memory shortage more gracefully
if (_m == NULL) error("Failed to allocate memory for the map");

View File

@ -26,8 +26,7 @@ extern void NORETURN CDECL error(const char *str, ...);
*/
Packet *NetworkSend_Init(const PacketType type)
{
Packet *packet;
MallocT(&packet, 1);
Packet *packet = MallocT<Packet>(1);
/* An error is inplace here, because it simply means we ran out of memory. */
if (packet == NULL) error("Failed to allocate Packet");

View File

@ -149,7 +149,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
if (cs->socket == INVALID_SOCKET) return NULL;
if (cs->packet_recv == NULL) {
MallocT(&cs->packet_recv, 1);
cs->packet_recv = MallocT<Packet>(1);
if (cs->packet_recv == NULL) error("Failed to allocate packet");
/* Set pos to zero! */
cs->packet_recv->pos = 0;

View File

@ -252,12 +252,12 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
switch (info->game_info_version) {
case 4: {
GRFConfig *c, **dst = &info->grfconfig;
GRFConfig **dst = &info->grfconfig;
uint i;
uint num_grfs = NetworkRecv_uint8(cs, p);
for (i = 0; i < num_grfs; i++) {
CallocT(&c, 1);
GRFConfig *c = CallocT<GRFConfig>(1);
NetworkRecv_GRFIdentifier(cs, p, c);
HandleIncomingNetworkGameInfoGRFConfig(c);

View File

@ -570,8 +570,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
{
CommandPacket *cp;
MallocT(&cp, 1);
CommandPacket *cp = MallocT<CommandPacket>(1);
cp->player = (PlayerID)NetworkRecv_uint8(MY_CLIENT, p);
cp->cmd = NetworkRecv_uint32(MY_CLIENT, p);
cp->p1 = NetworkRecv_uint32(MY_CLIENT, p);

View File

@ -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(NetworkClientState *cs, CommandPacket *cp)
// Prepare a DoCommand to be send over the network
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
{
CommandPacket *c;
MallocT(&c, 1);
CommandPacket *c = MallocT<CommandPacket>(1);
byte temp_callback;
c->player = _local_player;

View File

@ -26,7 +26,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
prev_item = item;
}
MallocT(&item, 1);
item = MallocT<NetworkGameList>(1);
memset(item, 0, sizeof(*item));
item->next = NULL;
item->ip = ip;

View File

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

View File

@ -793,8 +793,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
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

View File

@ -843,7 +843,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
}
/* Allocate station specs if necessary */
if (_cur_grffile->stations == NULL) CallocT(&_cur_grffile->stations, MAX_STATIONS);
if (_cur_grffile->stations == NULL) _cur_grffile->stations = CallocT<StationSpec*>(MAX_STATIONS);
statspec = &_cur_grffile->stations[stid];
@ -863,7 +863,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
uint32 classid;
/* Property 0x08 is special; it is where the station is allocated */
if (statspec[i] == NULL) CallocT(&statspec[i], 1);
if (statspec[i] == NULL) statspec[i] = CallocT<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, int numinfo, int prop, byte **bufp, int
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, int numinfo, int prop, byte **bufp, int
DrawTileSeqStruct *dtss;
// no relative bounding box support
ReallocT((DrawTileSeqStruct**)&dts->seq, ++seq_count);
dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count);
dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
dtss->delta_x = grf_load_byte(&buf);
@ -958,10 +958,10 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
//debug("l %d > %d ?", length, stat->lengths);
if (length > statspec->lengths) {
ReallocT(&statspec->platforms, length);
statspec->platforms = ReallocT(statspec->platforms, length);
memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths);
ReallocT(&statspec->layouts, length);
statspec->layouts = ReallocT(statspec->layouts, length);
memset(statspec->layouts + statspec->lengths, 0,
(length - statspec->lengths) * sizeof(*statspec->layouts));
@ -971,7 +971,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
//debug("p %d > %d ?", number, stat->platforms[l]);
if (number > statspec->platforms[l]) {
ReallocT(&statspec->layouts[l], number);
statspec->layouts[l] = ReallocT(statspec->layouts[l], number);
// We expect NULL being 0 here, but C99 guarantees that.
memset(statspec->layouts[l] + statspec->platforms[l], 0,
(number - statspec->platforms[l]) * sizeof(**statspec->layouts));
@ -980,7 +980,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
}
p = 0;
MallocT(&layout, length * number);
layout = MallocT<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, int numinfo, int prop, byte **bufp, int
if (bridge->sprite_table == NULL) {
/* Allocate memory for sprite table pointers and zero out */
CallocT(&bridge->sprite_table, 7);
bridge->sprite_table = CallocT<PalSpriteID*>(7);
}
for (; numtables-- != 0; tableid++) {
@ -1089,7 +1089,7 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
}
if (bridge->sprite_table[tableid] == NULL) {
MallocT(&bridge->sprite_table[tableid], 32);
bridge->sprite_table[tableid] = MallocT<PalSpriteID>(32);
}
for (sprite = 0; sprite < 32; sprite++)
@ -1596,7 +1596,7 @@ static void NewSpriteGroup(byte *buf, int len)
if (setid >= _cur_grffile->spritegroups_count) {
// Allocate memory for new sprite group references.
ReallocT(&_cur_grffile->spritegroups, setid + 1);
_cur_grffile->spritegroups = ReallocT(_cur_grffile->spritegroups, setid + 1);
// Initialise new space to NULL
for (; _cur_grffile->spritegroups_count < (setid + 1); _cur_grffile->spritegroups_count++)
_cur_grffile->spritegroups[_cur_grffile->spritegroups_count] = NULL;
@ -1641,7 +1641,7 @@ static void NewSpriteGroup(byte *buf, int len)
}
group->g.determ.num_adjusts++;
ReallocT(&group->g.determ.adjusts, group->g.determ.num_adjusts);
group->g.determ.adjusts = ReallocT(group->g.determ.adjusts, group->g.determ.num_adjusts);
adjust = &group->g.determ.adjusts[group->g.determ.num_adjusts - 1];
@ -1667,7 +1667,7 @@ static void NewSpriteGroup(byte *buf, int len)
} while (HASBIT(varadjust, 5));
group->g.determ.num_ranges = grf_load_byte(&buf);
CallocT(&group->g.determ.ranges, group->g.determ.num_ranges);
group->g.determ.ranges = CallocT<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, int len)
group->g.random.cmp_mode = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
group->g.random.lowest_randbit = grf_load_byte(&buf);
group->g.random.num_groups = grf_load_byte(&buf);
CallocT(&group->g.random.groups, group->g.random.num_groups);
group->g.random.groups = CallocT<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, int len)
group->g.real.num_loaded = num_loaded;
group->g.real.num_loading = num_loading;
if (num_loaded > 0) CallocT(&group->g.real.loaded, num_loaded);
if (num_loading > 0) CallocT(&group->g.real.loading, num_loading);
if (num_loaded > 0) group->g.real.loaded = CallocT<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 *buf, int len)
}
if (!wagover && last_engines_count != idcount) {
ReallocT(&last_engines, idcount);
last_engines = ReallocT(last_engines, idcount);
last_engines_count = idcount;
}
@ -2275,7 +2275,7 @@ static void CfgApply(byte *buf, int len)
/* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */
if (type == 0xFF) {
MallocT(&_preload_sprite, num);
_preload_sprite = MallocT<byte>(num);
FioReadBlock(_preload_sprite, num);
}
@ -3027,7 +3027,7 @@ static void DefineGotoLabel(byte *buf, int len)
if (!check_length(len, 1, "DefineGotoLabel")) return;
buf++; len--;
MallocT(&label, 1);
label = MallocT<GRFLabel>(1);
label->label = grf_load_byte(&buf);
label->nfo_line = _nfo_line;
label->pos = FioGetPos();
@ -3490,7 +3490,7 @@ static void InitNewGRFFile(const GRFConfig *config, int sprite_offset)
return;
}
CallocT(&newfile, 1);
newfile = CallocT<GRFFile>(1);
if (newfile == NULL) error ("Out of memory");
@ -3618,7 +3618,7 @@ static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
if (_preload_sprite == NULL) {
/* No preloaded sprite to work with; allocate and read the
* pseudo sprite content. */
MallocT(&buf, num);
buf = MallocT<byte>(num);
if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
FioReadBlock(buf, num);
} else {

View File

@ -119,12 +119,10 @@ void ClearGRFConfigList(GRFConfig **config)
* @return pointer to the last value added to the destination list */
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
{
GRFConfig *c;
/* Clear destination as it will be overwritten */
ClearGRFConfigList(dst);
for (; src != NULL; src = src->next) {
CallocT(&c, 1);
GRFConfig *c = CallocT<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, uint8 *md5sum, bool create)
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 */

View File

@ -83,7 +83,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
wos = &_engine_wagon_overrides[engine];
wos->overrides_count++;
ReallocT(&wos->overrides, wos->overrides_count);
wos->overrides = ReallocT(wos->overrides, wos->overrides_count);
wo = &wos->overrides[wos->overrides_count - 1];
/* FIXME: If we are replacing an override, release original SpriteGroup
@ -92,7 +92,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
wo->group = group;
wo->cargo = cargo;
wo->trains = trains;
MallocT(&wo->train_id, trains);
wo->train_id = MallocT<byte>(trains);
memcpy(wo->train_id, train_id, trains);
}

View File

@ -154,7 +154,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
case 6: /* Add selection to list */
if (WP(w, newgrf_add_d).sel != NULL) {
const GRFConfig *src = WP(w, newgrf_add_d).sel;
GRFConfig **list, *c;
GRFConfig **list;
/* Find last entry in the list, checking for duplicate grfid on the way */
for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) {
@ -165,7 +165,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
}
/* Copy GRF details from scanned list */
CallocT(&c, 1);
GRFConfig *c = CallocT<GRFConfig>(1);
*c = *src;
c->filename = strdup(src->filename);
if (src->name != NULL) c->name = strdup(src->name);

View File

@ -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 *statspec)
station_class = &station_classes[statspec->sclass];
i = station_class->stations++;
ReallocT(&station_class->spec, station_class->stations);
station_class->spec = ReallocT(station_class->spec, station_class->stations);
station_class->spec[i] = statspec;
statspec->allocated = true;
@ -607,7 +607,7 @@ int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec)
if (exec) {
if (i >= st->num_specs) {
st->num_specs = i + 1;
ReallocT(&st->speclist, st->num_specs);
st->speclist = ReallocT(st->speclist, st->num_specs);
if (st->num_specs == 2) {
/* Initial allocation */
@ -653,7 +653,7 @@ void DeallocateSpecFromStation(Station* st, byte specindex)
for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--);
if (st->num_specs > 1) {
ReallocT(&st->speclist, st->num_specs);
st->speclist = ReallocT(st->speclist, st->num_specs);
} else {
free(st->speclist);
st->num_specs = 0;

View File

@ -158,8 +158,7 @@ static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used.
char *TranslateTTDPatchCodes(const char *str)
{
char *tmp;
MallocT(&tmp, strlen(str) * 10 + 1); /* Allocate space to allow for expansion */
char *tmp = MallocT<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 *str)
}
*d = '\0';
ReallocT(&tmp, strlen(tmp) + 1);
tmp = ReallocT(tmp, strlen(tmp) + 1);
return tmp;
}

View File

@ -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);

View File

@ -120,7 +120,7 @@ void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
fseek(in, 0, SEEK_END);
len = ftell(in);
fseek(in, 0, SEEK_SET);
if (len > maxsize || !MallocT(&mem, len + 1)) {
if (len > maxsize || (mem = MallocT<byte>(len + 1)) == NULL) {
fclose(in);
return NULL;
}

View File

@ -49,15 +49,14 @@ static Queue* init_stack(Queue* q, uint max_size)
q->free = Stack_Free;
q->data.stack.max_size = max_size;
q->data.stack.size = 0;
MallocT(&q->data.stack.elements, max_size);
q->data.stack.elements = MallocT<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 max_size)
q->data.fifo.max_size = max_size;
q->data.fifo.head = 0;
q->data.fifo.tail = 0;
MallocT(&q->data.fifo.elements, max_size);
q->data.fifo.elements = MallocT<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 free_values)
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, void* item, int priority)
if (q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] == NULL) {
/* The currently allocated blocks are full, allocate a new one */
assert((q->data.binaryheap.size & BINARY_HEAP_BLOCKSIZE_MASK) == 0);
MallocT(&q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS], BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] = MallocT<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_size)
q->data.binaryheap.size = 0;
// We malloc memory in block of BINARY_HEAP_BLOCKSIZE
// It autosizes when it runs out of memory
CallocT(&q->data.binaryheap.elements, (max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
MallocT(&q->data.binaryheap.elements[0], BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.elements = CallocT<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_size)
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* hash, uint num_buckets)
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 key2, void* value)
node = h->buckets + hash;
} else {
/* Add it after prev */
MallocT(&node, 1);
node = MallocT<HashNode>(1);
prev->next = node;
}
node->next = NULL;

View File

@ -68,7 +68,6 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
BitmapFileHeader bfh;
BitmapInfoHeader bih;
RgbQuad rq[256];
Pixel *buff;
FILE *f;
uint i, padw;
uint n, maxlines;
@ -119,7 +118,7 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
maxlines = clamp(65536 / padw, 16, 128);
// now generate the bitmap bits
MallocT(&buff, padw * maxlines); // by default generate 128 lines at a time.
Pixel *buff = MallocT<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_structp png_ptr, png_const_charp message)
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
{
png_color rq[256];
Pixel *buff;
FILE *f;
uint i, y, n;
uint maxlines;
@ -226,7 +224,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
maxlines = clamp(65536 / w, 16, 128);
// now generate the bitmap bits
MallocT(&buff, w * maxlines); // by default generate 128 lines at a time.
Pixel *buff = MallocT<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 *name, ScreenshotCallback *callb, void *user
maxlines = clamp(65536 / w, 16, 128);
// now generate the bitmap bits
MallocT(&buff, w * maxlines); // by default generate 128 lines at a time.
Pixel *buff = MallocT<Pixel>(w * maxlines); // by default generate 128 lines at a time.
if (buff == NULL) {
fclose(f);
return false;

View File

@ -236,7 +236,7 @@ static IniFile *ini_load(const char *filename)
if (ns > a) {
a = max(a, 128U);
do a*=2; while (a < ns);
ReallocT(&comment, comment_alloc = a);
comment = ReallocT(comment, comment_alloc = a);
}
pos = comment_size;
comment_size += (e - s + 1);
@ -1509,8 +1509,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
if (group == NULL) return NULL;
for (item = group->item; item != NULL; item = item->next) {
GRFConfig *c;
CallocT(&c, 1);
GRFConfig *c = CallocT<GRFConfig>(1);
c->filename = strdup(item->name);
/* Parse parameters */

View File

@ -695,7 +695,7 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
for (page = &_patches_page[0]; page != endof(_patches_page); page++) {
uint i;
MallocT(&page->entries, page->num);
page->entries = MallocT<PatchEntry>(page->num);
for (i = 0; i != page->num; i++) {
uint index;
const SettingDesc *sd = GetPatchFromName(page->names[i], &index);

View File

@ -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 *mc, uint bank)
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);

View File

@ -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");

View File

@ -38,7 +38,7 @@ static SpriteCache *AllocateSpriteCache(uint index)
DEBUG(sprite, 4, "Increasing sprite cache to %d items (%d bytes)", items, items * sizeof(*_spritecache));
ReallocT(&_spritecache, items);
_spritecache = ReallocT(_spritecache, items);
if (_spritecache == NULL) {
error("Unable to allocate sprite cache of %d items (%d bytes)", items, items * sizeof(*_spritecache));

View File

@ -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);
}
}

View File

@ -198,13 +198,12 @@ static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities,
{
uint n = 0;
uint i, j;
const Station** station_sort;
const Station *st;
if (!(sl->flags & SL_REBUILD)) return;
/* Create array for sorting */
MallocT(&station_sort, GetMaxStationIndex() + 1);
const Station** station_sort = MallocT<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_d* sl, PlayerID owner, byte facilities,
}
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;

View File

@ -845,7 +845,7 @@ static void HandleString(char *str, bool master)
}
// 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 master)
}
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 master)
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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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(amplitude_t water_percent, height_t h_max_
height_t h_min, h_max, h_avg, h_water_level;
int water_tiles, desired_water_tiles;
height_t *h;
int *hist_buf, *hist;
int *hist;
HeightMapGetMinMaxAvg(&h_min, &h_max, &h_avg);
/* Allocate histogram buffer and clear its cells */
CallocT(&hist_buf, h_max - h_min + 1);
int *hist_buf = CallocT<int>(h_max - h_min + 1);
/* Fill histogram */
hist = HeightMapMakeHistogram(h_min, h_max, hist_buf);

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -2259,7 +2259,7 @@ static int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs)
static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *engine_list_length, uint16 step_size)
{
*engine_list_length = min(*engine_list_length + step_size, GetMaxVehicleIndex() + 1);
ReallocT((Vehicle ***)/* NO & */engine_list, *engine_list_length);
*engine_list = ReallocT(*engine_list, *engine_list_length);
}
/** Generates a list of vehicles inside a depot
@ -2436,7 +2436,7 @@ uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array
* We will still make it have room for 50 extra vehicles to prevent having
* to move the whole array if just one vehicle is added later */
*length_of_array = n + 50;
ReallocT((Vehicle***)/* NO & */sort_list, (*length_of_array) * sizeof((*sort_list)[0]));
*sort_list = ReallocT(*sort_list, (*length_of_array) * sizeof((*sort_list)[0]));
}
return n;
@ -2781,7 +2781,7 @@ UnitID GetFreeUnitNumber(byte type)
if (max > gmax) {
gmax = max;
free(cache);
MallocT(&cache, max + 1);
cache = MallocT<bool>(max + 1);
}
// Clear the cache

View File

@ -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;

View File

@ -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;

View File

@ -544,7 +544,7 @@ void AssignWidgetToWindow(Window *w, const Widget *widget)
for (wi = widget; wi->type != WWT_LAST; wi++) index++;
ReallocT(&w->widget, index);
w->widget = ReallocT(w->widget, index);
memcpy(w->widget, widget, sizeof(*w->widget) * index);
w->widget_count = index - 1;
} else {