Changeset - r11215:b3759139c3e1
[Not reviewed]
master
0 10 0
smatz - 16 years ago 2009-02-24 20:59:17
smatz@openttd.org
(svn r15568) -Cleanup: *allocT/AllocaM doesn't return NULL when allocating fails
10 files changed with 5 insertions and 50 deletions:
0 comments (0 inline, 0 general)
src/bmp.cpp
Show inline comments
 
@@ -331,7 +331,6 @@ bool BmpReadHeader(BmpBuffer *buffer, Bm
 
		if (info->palette_size == 0) info->palette_size = 1 << info->bpp;
 

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

	
 
		for (i = 0; i < info->palette_size; i++) {
 
			data->palette[i].b = ReadByte(buffer);
 
@@ -353,7 +352,6 @@ bool BmpReadBitmap(BmpBuffer *buffer, Bm
 
	assert(info != NULL && data != NULL);
 

	
 
	data->bitmap = CallocT<byte>(info->width * info->height * ((info->bpp == 24) ? 3 : 1));
 
	if (data->bitmap == NULL) return false;
 

	
 
	/* Load image */
 
	SetStreamOffset(buffer, info->offset);
src/fileio.cpp
Show inline comments
 
@@ -991,20 +991,17 @@ void SanitizeFilename(char *filename)
 

	
 
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
 
{
 
	FILE *in;
 
	byte *mem;
 
	size_t len;
 

	
 
	in = fopen(filename, "rb");
 
	FILE *in = fopen(filename, "rb");
 
	if (in == NULL) return NULL;
 

	
 
	fseek(in, 0, SEEK_END);
 
	len = ftell(in);
 
	size_t len = ftell(in);
 
	fseek(in, 0, SEEK_SET);
 
	if (len > maxsize || (mem = MallocT<byte>(len + 1)) == NULL) {
 
	if (len > maxsize) {
 
		fclose(in);
 
		return NULL;
 
	}
 
	byte *mem = MallocT<byte>(len + 1);
 
	mem[len] = 0;
 
	if (fread(mem, len, 1, in) != 1) {
 
		fclose(in);
src/heightmap.cpp
Show inline comments
 
@@ -137,14 +137,6 @@ static bool ReadHeightmapPNG(char *filen
 

	
 
	if (map != NULL) {
 
		*map = MallocT<byte>(info_ptr->width * info_ptr->height);
 

	
 
		if (*map == NULL) {
 
			ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_PNGMAP_ERROR, 0, 0);
 
			fclose(fp);
 
			png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
			return false;
 
		}
 

	
 
		ReadHeightmapPNGImageData(*map, png_ptr, info_ptr);
 
	}
 

	
 
@@ -253,15 +245,7 @@ static bool ReadHeightmapBMP(char *filen
 
		}
 

	
 
		*map = MallocT<byte>(info.width * info.height);
 
		if (*map == NULL) {
 
			ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_BMPMAP_ERROR, 0, 0);
 
			fclose(f);
 
			BmpDestroyData(&data);
 
			return false;
 
		}
 

	
 
		ReadHeightmapBMPImageData(*map, &info, &data);
 

	
 
	}
 

	
 
	BmpDestroyData(&data);
src/map.cpp
Show inline comments
 
@@ -52,11 +52,6 @@ void AllocateMap(uint size_x, uint size_
 
	free(_m);
 
	free(_me);
 

	
 
	/* 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 */
 
	_m = CallocT<Tile>(_map_size);
 
	_me = CallocT<TileExtended>(_map_size);
 
}
src/newgrf_storage.h
Show inline comments
 
@@ -75,8 +75,6 @@ struct PersistentStorageArray : BaseStor
 
		/* We do not have made a backup; lets do so */
 
		if (this->prev_storage != NULL) {
 
			this->prev_storage = MallocT<TYPE>(SIZE);
 
			if (this->prev_storage == NULL) return;
 

	
 
			memcpy(this->prev_storage, this->storage, sizeof(this->storage));
 

	
 
			/* We only need to register ourselves when we made the backup
src/queue.cpp
Show inline comments
 
@@ -34,7 +34,6 @@ static bool InsSort_Push(Queue *q, void 
 
{
 
	InsSortNode *newnode = MallocT<InsSortNode>(1);
 

	
 
	if (newnode == NULL) return false;
 
	newnode->item = item;
 
	newnode->priority = priority;
 
	if (q->data.inssort.first == NULL ||
src/screenshot.cpp
Show inline comments
 
@@ -127,10 +127,6 @@ static bool MakeBmpImage(const char *nam
 

	
 
	/* now generate the bitmap bits */
 
	void *buff = MallocT<uint8>(padw * maxlines * bpp); // by default generate 128 lines at a time.
 
	if (buff == NULL) {
 
		fclose(f);
 
		return false;
 
	}
 
	memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0
 

	
 
	/* start at the bottom, since bitmaps are stored bottom up. */
 
@@ -255,11 +251,6 @@ static bool MakePNGImage(const char *nam
 

	
 
	/* now generate the bitmap bits */
 
	void *buff = MallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
 
	if (buff == NULL) {
 
		png_destroy_write_struct(&png_ptr, &info_ptr);
 
		fclose(f);
 
		return false;
 
	}
 
	memset(buff, 0, w * maxlines * bpp);
 

	
 
	y = 0;
 
@@ -355,10 +346,6 @@ static bool MakePCXImage(const char *nam
 

	
 
	/* now generate the bitmap bits */
 
	uint8 *buff = MallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
 
	if (buff == NULL) {
 
		fclose(f);
 
		return false;
 
	}
 
	memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0
 

	
 
	y = 0;
src/sound.cpp
Show inline comments
 
@@ -111,7 +111,6 @@ static bool SetBankSource(MixerChannel *
 
	if (fe->file_size == 0) return false;
 

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

	
 
	FioSeekToFile(fe->file_slot, fe->file_offset);
 
	FioReadBlock(mem, fe->file_size);
src/sound/win32_s.cpp
Show inline comments
 
@@ -22,8 +22,7 @@ static void PrepareHeader(WAVEHDR *hdr)
 
	hdr->dwBufferLength = _bufsize * 4;
 
	hdr->dwFlags = 0;
 
	hdr->lpData = MallocT<char>(_bufsize * 4);
 
	if (hdr->lpData == NULL ||
 
			waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
 
	if (waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR)
 
		usererror("waveOutPrepareHeader failed");
 
}
 

	
src/tgp.cpp
Show inline comments
 
@@ -253,7 +253,6 @@ static inline bool AllocHeightMap()
 
	_height_map.total_size = (_height_map.size_x + 1) * (_height_map.size_y + 1);
 
	_height_map.dim_x = _height_map.size_x + 1;
 
	_height_map.h = CallocT<height_t>(_height_map.total_size);
 
	if (_height_map.h == NULL) return false;
 

	
 
	/* Iterate through height map initialize values */
 
	FOR_ALL_TILES_IN_HEIGHT(h) *h = _invalid_height;
0 comments (0 inline, 0 general)