Commit d1e3c8cd authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix type to match return value of read.

parent fd23ce82
...@@ -3,16 +3,17 @@ ...@@ -3,16 +3,17 @@
#endif #endif
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> // gettimeofday() #include <sys/time.h> // gettimeofday()
#include <fcntl.h>
#include "dmemory.h" #include "dmemory.h"
#include "error.h" #include "error.h"
...@@ -918,7 +919,7 @@ void file_set_buffer(bfile_t *fileptr) ...@@ -918,7 +919,7 @@ void file_set_buffer(bfile_t *fileptr)
static static
int file_fill_buffer(bfile_t *fileptr) int file_fill_buffer(bfile_t *fileptr)
{ {
long nread; ssize_t nread;
int fd; int fd;
long offset = 0; long offset = 0;
off_t retseek; off_t retseek;
...@@ -943,7 +944,8 @@ int file_fill_buffer(bfile_t *fileptr) ...@@ -943,7 +944,8 @@ int file_fill_buffer(bfile_t *fileptr)
} }
else else
{ {
nread = fileptr->bufferSize; xassert(fileptr->bufferSize <= SSIZE_MAX);
nread = (ssize_t)fileptr->bufferSize;
if ( (nread + fileptr->bufferPos) > fileptr->size ) if ( (nread + fileptr->bufferPos) > fileptr->size )
nread = fileptr->size - fileptr->bufferPos; nread = fileptr->size - fileptr->bufferPos;
...@@ -955,7 +957,7 @@ int file_fill_buffer(bfile_t *fileptr) ...@@ -955,7 +957,7 @@ int file_fill_buffer(bfile_t *fileptr)
fileptr->buffer = NULL; fileptr->buffer = NULL;
} }
fileptr->mappedSize = (size_t) nread; fileptr->mappedSize = (size_t)nread;
fileptr->buffer = (char*) mmap(NULL, (size_t) nread, PROT_READ, MAP_PRIVATE, fd, fileptr->bufferPos); fileptr->buffer = (char*) mmap(NULL, (size_t) nread, PROT_READ, MAP_PRIVATE, fd, fileptr->bufferPos);
...@@ -971,7 +973,7 @@ int file_fill_buffer(bfile_t *fileptr) ...@@ -971,7 +973,7 @@ int file_fill_buffer(bfile_t *fileptr)
if ( retseek == (off_t)-1 ) if ( retseek == (off_t)-1 )
SysError("lseek error at pos %ld file %s", (long) fileptr->bufferPos, fileptr->name); SysError("lseek error at pos %ld file %s", (long) fileptr->bufferPos, fileptr->name);
nread = (long) read(fd, fileptr->buffer, fileptr->bufferSize); nread = read(fd, fileptr->buffer, fileptr->bufferSize);
} }
if ( nread <= 0 ) if ( nread <= 0 )
...@@ -986,7 +988,7 @@ int file_fill_buffer(bfile_t *fileptr) ...@@ -986,7 +988,7 @@ int file_fill_buffer(bfile_t *fileptr)
} }
fileptr->bufferPtr = fileptr->buffer; fileptr->bufferPtr = fileptr->buffer;
fileptr->bufferCnt = nread; fileptr->bufferCnt = (size_t)nread;
fileptr->bufferStart = fileptr->bufferPos; fileptr->bufferStart = fileptr->bufferPos;
fileptr->bufferPos += nread; fileptr->bufferPos += nread;
...@@ -1009,7 +1011,7 @@ int file_fill_buffer(bfile_t *fileptr) ...@@ -1009,7 +1011,7 @@ int file_fill_buffer(bfile_t *fileptr)
Error("Internal problem with buffer handling. nread = %d offset = %d", nread, offset); Error("Internal problem with buffer handling. nread = %d offset = %d", nread, offset);
fileptr->bufferPtr += offset; fileptr->bufferPtr += offset;
fileptr->bufferCnt -= offset; fileptr->bufferCnt -= (size_t)offset;
} }
fileptr->bufferNumFill++; fileptr->bufferNumFill++;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment