mirror of https://github.com/mgba-emu/mgba.git
VFS: Early return NULL if attempting to map 0 bytes from a file
This commit is contained in:
parent
55c2efa3ea
commit
31f798748b
1
CHANGES
1
CHANGES
|
@ -112,6 +112,7 @@ Misc:
|
|||
- Qt: Resume crashed game when loading a save state
|
||||
- SDL: Support exposing an axis directly as the gyro value (closes mgba.io/i/2531)
|
||||
- Windows: Attach to console if present
|
||||
- VFS: Early return NULL if attempting to map 0 bytes from a file
|
||||
- Vita: Add bilinear filtering option (closes mgba.io/i/344)
|
||||
|
||||
0.9.3: (2021-12-17)
|
||||
|
|
|
@ -137,6 +137,9 @@ ssize_t _vf3dWrite(struct VFile* vf, const void* buffer, size_t size) {
|
|||
static void* _vf3dMap(struct VFile* vf, size_t size, int flags) {
|
||||
struct VFile3DS* vf3d = (struct VFile3DS*) vf;
|
||||
UNUSED(flags);
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
void* buffer = anonymousMemoryMap(size);
|
||||
if (buffer) {
|
||||
u32 sizeRead;
|
||||
|
|
|
@ -113,6 +113,9 @@ ssize_t _vfsceWrite(struct VFile* vf, const void* buffer, size_t size) {
|
|||
static void* _vfsceMap(struct VFile* vf, size_t size, int flags) {
|
||||
struct VFileSce* vfsce = (struct VFileSce*) vf;
|
||||
UNUSED(flags);
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
void* buffer = anonymousMemoryMap(size);
|
||||
if (buffer) {
|
||||
SceOff cur = sceIoLseek(vfsce->fd, 0, SEEK_CUR);
|
||||
|
|
|
@ -134,6 +134,9 @@ ssize_t _vfdWrite(struct VFile* vf, const void* buffer, size_t size) {
|
|||
#ifdef _POSIX_MAPPED_FILES
|
||||
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
||||
struct VFileFD* vfd = (struct VFileFD*) vf;
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
int mmapFlags = MAP_PRIVATE;
|
||||
if (flags & MAP_WRITE) {
|
||||
mmapFlags = MAP_SHARED;
|
||||
|
@ -153,6 +156,9 @@ static void _vfdUnmap(struct VFile* vf, void* memory, size_t size) {
|
|||
#elif defined(_WIN32)
|
||||
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
||||
struct VFileFD* vfd = (struct VFileFD*) vf;
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
int createFlags = PAGE_WRITECOPY;
|
||||
int mapFiles = FILE_MAP_COPY;
|
||||
if (flags & MAP_WRITE) {
|
||||
|
@ -192,12 +198,16 @@ static void _vfdUnmap(struct VFile* vf, void* memory, size_t size) {
|
|||
#else
|
||||
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
|
||||
struct VFileFD* vfd = (struct VFileFD*) vf;
|
||||
if (!size) {
|
||||
vfd->writable = false;
|
||||
return NULL;
|
||||
}
|
||||
if (flags & MAP_WRITE) {
|
||||
vfd->writable = true;
|
||||
}
|
||||
void* mem = anonymousMemoryMap(size);
|
||||
if (!mem) {
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
off_t pos = lseek(vfd->fd, 0, SEEK_CUR);
|
||||
|
|
Loading…
Reference in New Issue