From 05bc3af03d399bfd9e7584236383dd69cdbb0c59 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Sat, 22 Jan 2022 18:40:27 -0500 Subject: [PATCH] Use size_t rather than int to track dynamic buffer size. This lets use create dynamic buffers larger than 2GB. --- src/calendar.c | 2 +- src/dynbuf.c | 4 ++-- src/dynbuf.h | 4 ++-- src/funcs.c | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/calendar.c b/src/calendar.c index a7284a4a..a3cf33cc 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1336,7 +1336,7 @@ static void WriteCalTrailer(void) /***************************************************************/ static int DoCalRem(ParsePtr p, int col) { - int oldLen; + size_t oldLen; Trigger trig; TimeTrig tim; Value v; diff --git a/src/dynbuf.c b/src/dynbuf.c index eb331acd..40b385d9 100644 --- a/src/dynbuf.c +++ b/src/dynbuf.c @@ -27,11 +27,11 @@ Doubles the size of dynamic buffer until it has room for at least 'n' characters, not including trailing '\0' **********************************************************************/ -static int DBufMakeRoom(DynamicBuffer *dbuf, int n) +static int DBufMakeRoom(DynamicBuffer *dbuf, size_t n) { /* Double size until it's greater than n (strictly > to leave room for trailing '\0' */ - int size = dbuf->allocatedLen; + size_t size = dbuf->allocatedLen; char *buf; if (size > n) return OK; diff --git a/src/dynbuf.h b/src/dynbuf.h index de0b90b2..b02a474d 100644 --- a/src/dynbuf.h +++ b/src/dynbuf.h @@ -17,8 +17,8 @@ #define DBUF_STATIC_SIZE 128 typedef struct { char *buffer; - int len; - int allocatedLen; + size_t len; + size_t allocatedLen; char staticBuf[DBUF_STATIC_SIZE]; } DynamicBuffer; diff --git a/src/funcs.c b/src/funcs.c index c0334b00..ea486693 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -433,7 +433,9 @@ static int FStrlen(func_info *info) Value *v = &ARG(0); if (v->type != STR_TYPE) return E_BAD_TYPE; RetVal.type = INT_TYPE; - RETVAL = strlen(v->v.str); + size_t l = strlen(v->v.str); + if (l > INT_MAX) return E_2HIGH; + RETVAL = (int) l; return OK; } @@ -1594,7 +1596,7 @@ static int FShell(func_info *info) DBufFree(&buf); return E_NO_MEM; } - if (maxlen > 0 && DBufLen(&buf) >= maxlen) { + if (maxlen > 0 && DBufLen(&buf) >= (size_t) maxlen) { break; } }