(svn r15568) -Cleanup: *allocT/AllocaM doesn't return NULL when allocating fails

This commit is contained in:
smatz 2009-02-24 20:59:17 +00:00
parent 8beca127dd
commit d73c1fa7bf
10 changed files with 5 additions and 50 deletions

View File

@ -331,7 +331,6 @@ bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
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, BmpInfo *info, BmpData *data)
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);

View File

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

View File

@ -137,14 +137,6 @@ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
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 *filename, uint *x, uint *y, byte **map)
}
*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);

View File

@ -52,11 +52,6 @@ void AllocateMap(uint size_x, uint size_y)
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);
}

View File

@ -75,8 +75,6 @@ struct PersistentStorageArray : BaseStorageArray {
/* 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

View File

@ -34,7 +34,6 @@ static bool InsSort_Push(Queue *q, void *item, int priority)
{
InsSortNode *newnode = MallocT<InsSortNode>(1);
if (newnode == NULL) return false;
newnode->item = item;
newnode->priority = priority;
if (q->data.inssort.first == NULL ||

View File

@ -127,10 +127,6 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
/* 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 *name, ScreenshotCallback *callb, void *user
/* 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 *name, ScreenshotCallback *callb, void *user
/* 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;

View File

@ -111,7 +111,6 @@ static bool SetBankSource(MixerChannel *mc, const FileEntry *fe)
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);

View File

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

View File

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