Browse Source

instead of calling mmap with a size of 0 (which will fail), skip the

syscall and fail directly
master
Felix von Leitner 4 years ago
parent
commit
25835d0c1d
4 changed files with 4 additions and 4 deletions
  1. +1
    -1
      mmap/mmap_private.c
  2. +1
    -1
      mmap/mmap_read.c
  3. +1
    -1
      mmap/mmap_readat.c
  4. +1
    -1
      mmap/mmap_shared.c

+ 1
- 1
mmap/mmap_private.c View File

@ -28,7 +28,7 @@ char* mmap_private(const char* filename,size_t * filesize) {
char *map;
if (fd>=0) {
register off_t o=lseek(fd,0,SEEK_END);
if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; }
if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; }
*filesize=(size_t)o;
map=(char*)mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
if (map==(char*)-1)


+ 1
- 1
mmap/mmap_read.c View File

@ -28,7 +28,7 @@ extern const char* mmap_read(const char* filename,size_t * filesize) {
char *map;
if (fd>=0) {
register off_t o=lseek(fd,0,SEEK_END);
if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; }
if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; }
*filesize=(size_t)o;
if (o>0) {
map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0);


+ 1
- 1
mmap/mmap_readat.c View File

@ -20,7 +20,7 @@ extern const char* mmap_readat(const char* filename,size_t * filesize,int dirfd)
char *map;
if (fd>=0) {
register off_t o=lseek(fd,0,SEEK_END);
if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; }
if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; }
*filesize=(size_t)o;
if (o>0) {
map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0);


+ 1
- 1
mmap/mmap_shared.c View File

@ -28,7 +28,7 @@ extern char* mmap_shared(const char* filename,size_t * filesize) {
char *map;
if (fd>=0) {
register off_t o=lseek(fd,0,SEEK_END);
if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; }
if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; }
*filesize=(size_t)o;
if (o) {
map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);


Loading…
Cancel
Save