(svn r11600) -Cleanup: remove extra out-of-memory checks, since it's now done in *allocT functions.
authorglx
Sat, 08 Dec 2007 15:47:23 +0000
changeset 8040 92c69fcd0d61
parent 8039 fa18f4352154
child 8041 9483d3e46b3e
(svn r11600) -Cleanup: remove extra out-of-memory checks, since it's now done in *allocT functions.
src/group_gui.cpp
src/industry_gui.cpp
src/map.cpp
src/network/network_gui.cpp
src/newgrf.cpp
src/oldpool.cpp
src/signs_gui.cpp
src/spritecache.cpp
src/station_gui.cpp
src/town_gui.cpp
--- a/src/group_gui.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/group_gui.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -43,9 +43,6 @@
 	if (!(gl->l.flags & VL_REBUILD)) return;
 
 	list = MallocT<const Group*>(GetGroupArraySize());
-	if (GetGroupArraySize() != 0 && list == NULL) {
-		error("Could not allocate memory for the group-sorting-list");
-	}
 
 	FOR_ALL_GROUPS(g) {
 		if (g->owner == owner && g->vehicle_type == vehicle_type) list[n++] = g;
@@ -53,9 +50,6 @@
 
 	free((void*)gl->sort_list);
 	gl->sort_list = MallocT<const Group *>(n);
-	if (n != 0 && gl->sort_list == NULL) {
-		error("Could not allocate memory for the group-sorting-list");
-	}
 	gl->l.list_length = n;
 
 	for (uint i = 0; i < n; ++i) gl->sort_list[i] = list[i];
--- a/src/industry_gui.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/industry_gui.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -752,7 +752,6 @@
 
 	/* Create array for sorting */
 	_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
-	if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
 
 	/* Don't attempt a sort if there are no industries */
 	if (GetNumIndustries() != 0) {
--- a/src/map.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/map.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -52,14 +52,13 @@
 	free(_m);
 	free(_me);
 
-	_m = CallocT<Tile>(_map_size);
-	_me = CallocT<TileExtended>(_map_size);
-
 	/* XXX @todo handle memory shortage more gracefully
+	 * CallocT does the out-of-memory check
 	 * Maybe some attemps could be made to try with smaller maps down to 64x64
 	 * Maybe check for available memory before doing the calls, after all, we know how big
 	 * the map is */
-	if ((_m == NULL) || (_me == NULL)) error("Failed to allocate memory for the map");
+	_m = CallocT<Tile>(_map_size);
+	_me = CallocT<TileExtended>(_map_size);
 }
 
 
--- a/src/network/network_gui.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/network/network_gui.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -167,7 +167,6 @@
 	/* Create temporary array of games to use for listing */
 	free(nqld->sort_list);
 	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;
 
 	for (n = 0, ngl_temp = _network_game_list; ngl_temp != NULL; ngl_temp = ngl_temp->next) {
--- a/src/newgrf.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/newgrf.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -5421,7 +5421,6 @@
 		/* No preloaded sprite to work with; allocate and read the
 		 * pseudo sprite content. */
 		buf = MallocT<byte>(num);
-		if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
 		FioReadBlock(buf, num);
 	} else {
 		/* Use the preloaded sprite data. */
--- a/src/oldpool.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/oldpool.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -55,12 +55,9 @@
 
 	/* Increase the poolsize */
 	this->blocks = ReallocT(this->blocks, this->current_blocks + 1);
-	if (this->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", this->name);
 
 	/* Allocate memory to the new block item */
 	this->blocks[this->current_blocks] = MallocT<byte>(this->item_size * (1 << this->block_size_bits));
-	if (this->blocks[this->current_blocks] == NULL)
-		error("Pool: (%s) could not allocate memory for blocks", this->name);
 
 	/* Clean the content of the new block */
 	memset(this->blocks[this->current_blocks], 0, this->item_size * (1 << this->block_size_bits));
--- a/src/signs_gui.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/signs_gui.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -47,7 +47,6 @@
 
 	/* Create array for sorting */
 	_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;
 	_num_sign_sort = n;
--- a/src/spritecache.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/spritecache.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -53,10 +53,6 @@
 
 		_spritecache = ReallocT(_spritecache, items);
 
-		if (_spritecache == NULL) {
-			error("Unable to allocate sprite cache of %d items (%d bytes)", items, items * sizeof(*_spritecache));
-		}
-
 		/* Reset the new items and update the count */
 		memset(_spritecache + _spritecache_items, 0, (items - _spritecache_items) * sizeof(*_spritecache));
 		_spritecache_items = items;
@@ -411,8 +407,7 @@
 
 	/* Display an error message and die, in case we found no sprite at all.
 	 * This shouldn't really happen, unless all sprites are locked. */
-	if (best == (uint)-1)
-		error("Out of sprite memory");
+	if (best == (uint)-1) error("Out of sprite memory");
 
 	/* Mark the block as free (the block must be in use) */
 	s = (MemBlock*)GetSpriteCache(best)->ptr - 1;
--- a/src/station_gui.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/station_gui.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -228,7 +228,6 @@
 
 	/* Create array for sorting */
 	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);
 
@@ -255,7 +254,6 @@
 
 	free((void*)sl->sort_list);
 	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;
 
 	for (uint i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
--- a/src/town_gui.cpp	Sat Dec 08 15:21:37 2007 +0000
+++ b/src/town_gui.cpp	Sat Dec 08 15:47:23 2007 +0000
@@ -449,7 +449,6 @@
 
 	/* Create array for sorting */
 	_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;