From 277f92284c31b0dd0328094ac2e393735fa0ac11 Mon Sep 17 00:00:00 2001 From: huangzhw Date: Wed, 6 Jan 2021 00:41:53 +0800 Subject: [PATCH] sdscatfmt call sdsMakeRoomFor, asked for more space than intended (#8286) instead of asking for the extra new space it wanted, it asked to grow the string by the size it already has too. i.e. a string of 1000 bytes, needing to grow by 10 bytes, would have been asking for an **additional** 1010 bytes. (cherry picked from commit f2bde2268a5420ed2d481fc0141cb73de0b1f200) --- src/sds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sds.c b/src/sds.c index a723a42c3..965badf13 100644 --- a/src/sds.c +++ b/src/sds.c @@ -606,7 +606,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) { /* To avoid continuous reallocations, let's start with a buffer that * can hold at least two times the format string itself. It's not the * best heuristic but seems to work in practice. */ - s = sdsMakeRoomFor(s, initlen + strlen(fmt)*2); + s = sdsMakeRoomFor(s, strlen(fmt)*2); va_start(ap,fmt); f = fmt; /* Next format specifier byte to process. */ i = initlen; /* Position of the next byte to write to dest str. */