Commit c951c3ee authored by antirez's avatar antirez
Browse files

Fix undefined behavior in ll2string().

The bug was found by @CAFxX, thanks!
See issue #1940.
parent 78a012d8
...@@ -261,7 +261,11 @@ int ll2string(char* dst, size_t dstlen, long long svalue) { ...@@ -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 /* The main loop works with 64bit unsigned integers for simplicity, so
* we convert the number here and remember if it is negative. */ * we convert the number here and remember if it is negative. */
if (svalue < 0) { if (svalue < 0) {
value = -svalue; if (svalue != LLONG_MIN) {
value = -svalue;
} else {
value = ((unsigned long long) LLONG_MAX)+1;
}
negative = 1; negative = 1;
} else { } else {
value = svalue; value = svalue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment