summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Svensson <bjorn.a.svensson@est.tech>2022-02-02 10:44:52 +0100
committerBjörn Svensson <bjorn.a.svensson@est.tech>2022-02-02 10:44:52 +0100
commit00b82683bbec3652f836518c30fecdb0f5a3ea62 (patch)
tree767a21b7cc474013b87134aae3545a9ab8dc4853
parent64062a1d40f558e0892ed0a7566d389c4e6eb904 (diff)
Handle overflows as errors instead of asserting
-rw-r--r--sds.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sds.c b/sds.c
index 01b00f3..a20ba19 100644
--- a/sds.c
+++ b/sds.c
@@ -90,7 +90,7 @@ sds sdsnewlen(const void *init, size_t initlen) {
int hdrlen = sdsHdrSize(type);
unsigned char *fp; /* flags pointer. */
- assert(initlen + hdrlen + 1 > initlen); /* Catch size_t overflow */
+ if (hdrlen+initlen+1 <= initlen) return NULL; /* Catch size_t overflow */
sh = s_malloc(hdrlen+initlen+1);
if (sh == NULL) return NULL;
if (!init)
@@ -207,7 +207,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
len = sdslen(s);
sh = (char*)s-sdsHdrSize(oldtype);
reqlen = newlen = (len+addlen);
- assert(newlen > len); /* Catch size_t overflow */
+ if (newlen <= len) return NULL; /* Catch size_t overflow */
if (newlen < SDS_MAX_PREALLOC)
newlen *= 2;
else
@@ -221,7 +221,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
if (type == SDS_TYPE_5) type = SDS_TYPE_8;
hdrlen = sdsHdrSize(type);
- assert(hdrlen + newlen + 1 > reqlen); /* Catch size_t overflow */
+ if (hdrlen+newlen+1 <= reqlen) return NULL; /* Catch size_t overflow */
if (oldtype==type) {
newsh = s_realloc(sh, hdrlen+newlen+1);
if (newsh == NULL) return NULL;