From d73c1fa7bfed01a187e14c4d86cde70e7121c51b Mon Sep 17 00:00:00 2001 From: smatz Date: Tue, 24 Feb 2009 20:59:17 +0000 Subject: (svn r15568) -Cleanup: *allocT/AllocaM doesn't return NULL when allocating fails --- src/bmp.cpp | 2 -- src/fileio.cpp | 11 ++++------- src/heightmap.cpp | 16 ---------------- src/map.cpp | 5 ----- src/newgrf_storage.h | 2 -- src/queue.cpp | 1 - src/screenshot.cpp | 13 ------------- src/sound.cpp | 1 - src/sound/win32_s.cpp | 3 +-- src/tgp.cpp | 1 - 10 files changed, 5 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/bmp.cpp b/src/bmp.cpp index 7e025964e..ae277d7c8 100644 --- a/src/bmp.cpp +++ b/src/bmp.cpp @@ -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(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(info->width * info->height * ((info->bpp == 24) ? 3 : 1)); - if (data->bitmap == NULL) return false; /* Load image */ SetStreamOffset(buffer, info->offset); diff --git a/src/fileio.cpp b/src/fileio.cpp index 19f4f4de1..59620df5c 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -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(len + 1)) == NULL) { + if (len > maxsize) { fclose(in); return NULL; } + byte *mem = MallocT(len + 1); mem[len] = 0; if (fread(mem, len, 1, in) != 1) { fclose(in); diff --git a/src/heightmap.cpp b/src/heightmap.cpp index 233f5952e..b690438d4 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -137,14 +137,6 @@ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map) if (map != NULL) { *map = MallocT(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(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); diff --git a/src/map.cpp b/src/map.cpp index 77952cc2f..ba6c82dba 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -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(_map_size); _me = CallocT(_map_size); } diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index e3320d055..be576f9c2 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -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(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 diff --git a/src/queue.cpp b/src/queue.cpp index d84efb1ba..50ce7d289 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -34,7 +34,6 @@ static bool InsSort_Push(Queue *q, void *item, int priority) { InsSortNode *newnode = MallocT(1); - if (newnode == NULL) return false; newnode->item = item; newnode->priority = priority; if (q->data.inssort.first == NULL || diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 8b0aa4530..960c08416 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -127,10 +127,6 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user /* now generate the bitmap bits */ void *buff = MallocT(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(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(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; diff --git a/src/sound.cpp b/src/sound.cpp index 586d12c1a..9995ec190 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -111,7 +111,6 @@ static bool SetBankSource(MixerChannel *mc, const FileEntry *fe) if (fe->file_size == 0) return false; int8 *mem = MallocT(fe->file_size); - if (mem == NULL) return false; FioSeekToFile(fe->file_slot, fe->file_offset); FioReadBlock(mem, fe->file_size); diff --git a/src/sound/win32_s.cpp b/src/sound/win32_s.cpp index 1bb0e9d53..3a5419495 100644 --- a/src/sound/win32_s.cpp +++ b/src/sound/win32_s.cpp @@ -22,8 +22,7 @@ static void PrepareHeader(WAVEHDR *hdr) hdr->dwBufferLength = _bufsize * 4; hdr->dwFlags = 0; hdr->lpData = MallocT(_bufsize * 4); - if (hdr->lpData == NULL || - waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) + if (waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) usererror("waveOutPrepareHeader failed"); } diff --git a/src/tgp.cpp b/src/tgp.cpp index 4916e97a4..c12fb5dd8 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -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_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; -- cgit v1.2.3-54-g00ecf