# HG changeset patch # User smatz # Date 2009-02-24 20:59:17 # Node ID b3759139c3e10ff38943ee818a3629fcad103b3d # Parent df820ada71fcca202991c5f4df726045d8619284 (svn r15568) -Cleanup: *allocT/AllocaM doesn't return NULL when allocating fails diff --git a/src/bmp.cpp b/src/bmp.cpp --- a/src/bmp.cpp +++ b/src/bmp.cpp @@ -331,7 +331,6 @@ bool BmpReadHeader(BmpBuffer *buffer, Bm 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, Bm 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 --- 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 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -137,14 +137,6 @@ static bool ReadHeightmapPNG(char *filen 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 *filen } *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 --- a/src/map.cpp +++ b/src/map.cpp @@ -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(_map_size); _me = CallocT(_map_size); } diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -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(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 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -34,7 +34,6 @@ static bool InsSort_Push(Queue *q, void { 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 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -127,10 +127,6 @@ static bool MakeBmpImage(const char *nam /* 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 *nam /* 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 *nam /* 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 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -111,7 +111,6 @@ static bool SetBankSource(MixerChannel * 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 --- 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 --- 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;