From b676f9c3e2381af56323375af1abece6095a4e9e Mon Sep 17 00:00:00 2001 From: Spoike Date: Sun, 31 Oct 2021 18:20:22 +0000 Subject: [PATCH] Allow for bigger map-packs. Hopefully everyone is running a 64bit system now... git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6091 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/http/httpclient.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/engine/http/httpclient.c b/engine/http/httpclient.c index 169655ca..70eed1bd 100644 --- a/engine/http/httpclient.c +++ b/engine/http/httpclient.c @@ -1773,9 +1773,9 @@ typedef struct vfsfile_t funcs; char *data; - int maxlen; - unsigned int writepos; - unsigned int readpos; + size_t maxlen; + size_t writepos; + size_t readpos; void *mutex; int refs; qboolean terminate; //one end has closed, make the other report failures now that its no longer needed. @@ -1842,6 +1842,8 @@ static int QDECL VFSPIPE_ReadBytes(vfsfile_t *f, void *buffer, int len) static int QDECL VFSPIPE_WriteBytes(vfsfile_t *f, const void *buffer, int len) { vfspipe_t *p = (vfspipe_t*)f; + if (len < 0) + return -1; Sys_LockMutex(p->mutex); if (p->terminate) { //if we started with 2 refs, and we're down to one, and we're writing, then its the reader that closed. that means writing is redundant and we should signal an error. @@ -1860,15 +1862,15 @@ static int QDECL VFSPIPE_WriteBytes(vfsfile_t *f, const void *buffer, int len) p->maxlen = p->writepos + len; if (p->maxlen < (p->writepos-p->readpos)*2) //over-allocate a little p->maxlen = (p->writepos-p->readpos)*2; - if (p->maxlen > 0x8000000) + if (p->maxlen > 0x8000000 && p->data) { - p->maxlen = 0x8000000; - len = p->maxlen - p->writepos; - if (!len) + p->maxlen = max(p->writepos,0x8000000); + if (p->maxlen <= p->writepos) { Sys_UnlockMutex(p->mutex); return -1; //try and get the caller to stop } + len = min(len, p->maxlen - p->writepos); } p->data = realloc(p->data, p->maxlen); }