mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
Putting try { ... } catch(std::bad_alloc &) { ... } around recently introduced resize() calls
At the very least, I suppose this doesn't hurt; I'd just like to discuss how this should work in the long run. Also, this blog entry sums up my opinion perfectly: http://christiangarbin.blogspot.com/2013/05/the-futility-of-catching-stdbadalloc.html
This commit is contained in:
parent
5f3bb35b12
commit
f83fce0c28
@ -208,7 +208,8 @@ static imgtoolerr_t imgtool_floppy_read_sector(imgtool_image *image, UINT32 trac
|
||||
return imgtool_floppy_error(ferr);
|
||||
|
||||
// resize the buffer accordingly
|
||||
buffer.resize(sector_size);
|
||||
try { buffer.resize(sector_size); }
|
||||
catch (std::bad_alloc& b) { return IMGTOOLERR_OUTOFMEMORY; }
|
||||
|
||||
// and read the sector
|
||||
ferr = floppy_read_sector(imgtool_floppy(image), head, track, sector, 0, &buffer[0], sector_size);
|
||||
|
@ -1818,7 +1818,9 @@ static imgtoolerr_t amiga_image_read_sector(imgtool_image* img, UINT32 track, UI
|
||||
static imgtoolerr_t amiga_image_read_sector(imgtool_image* img,
|
||||
UINT32 track, UINT32 head, UINT32 sector, std::vector<UINT8> &buffer)
|
||||
{
|
||||
buffer.resize(BSIZE);
|
||||
try { buffer.resize(BSIZE); }
|
||||
catch (std::bad_alloc& b) { return IMGTOOLERR_OUTOFMEMORY; }
|
||||
|
||||
return amiga_image_read_sector(img, track, head, sector, &buffer[0], buffer.size());
|
||||
}
|
||||
|
||||
|
@ -346,7 +346,8 @@ static imgtoolerr_t pc_chd_image_readsector(imgtool_image *image, UINT32 track,
|
||||
|
||||
// get the sector size and resize the buffer
|
||||
UINT32 sector_size = imghd_get_header(&info->hard_disk)->sectorbytes;
|
||||
buffer.resize(sector_size);
|
||||
try { buffer.resize(sector_size); }
|
||||
catch (std::bad_alloc& b) { return IMGTOOLERR_OUTOFMEMORY; }
|
||||
|
||||
// read the data
|
||||
return imghd_read(&info->hard_disk,
|
||||
|
@ -811,7 +811,8 @@ static imgtoolerr_t thom_read_sector(imgtool_image* img, UINT32 track,
|
||||
return IMGTOOLERR_SEEKERROR;
|
||||
|
||||
// resize the buffer
|
||||
buffer.resize(f->sector_size);
|
||||
try { buffer.resize(f->sector_size); }
|
||||
catch (std::bad_alloc& b) { return IMGTOOLERR_OUTOFMEMORY; }
|
||||
|
||||
memcpy( &buffer[0], thom_get_sector( f, head, track, sector ), f->sector_size);
|
||||
return IMGTOOLERR_SUCCESS;
|
||||
|
Loading…
Reference in New Issue
Block a user