From ca7d9f42b3d159d01123492f87b2249a0053567c Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 15 Aug 2014 15:48:15 +0200 Subject: [PATCH] Fix undefined behavior in ll2string(). The bug was found by @CAFxX, thanks! See issue #1940. --- src/util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index a0bb2b84c..1b1798658 100644 --- a/src/util.c +++ b/src/util.c @@ -261,7 +261,11 @@ int ll2string(char* dst, size_t dstlen, long long svalue) { /* The main loop works with 64bit unsigned integers for simplicity, so * we convert the number here and remember if it is negative. */ if (svalue < 0) { - value = -svalue; + if (svalue != LLONG_MIN) { + value = -svalue; + } else { + value = ((unsigned long long) LLONG_MAX)+1; + } negative = 1; } else { value = svalue;