From 2d86995273e431b40c2bd30c694ea405cc698118 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 15 Jun 2016 12:48:58 +0200 Subject: [PATCH] GETRANGE: return empty string with negative, inverted start/end. --- src/bitops.c | 4 ++-- src/t_string.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bitops.c b/src/bitops.c index 2312432fc..781cc58d6 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -773,12 +773,12 @@ void bitcountCommand(client *c) { if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK) return; /* Convert negative indexes */ - if (start < 0) start = strlen+start; - if (end < 0) end = strlen+end; if (start < 0 && end < 0 && start > end) { addReply(c,shared.czero); return; } + if (start < 0) start = strlen+start; + if (end < 0) end = strlen+end; if (start < 0) start = 0; if (end < 0) end = 0; if (end >= strlen) end = strlen-1; diff --git a/src/t_string.c b/src/t_string.c index 35eb9d7c1..8c737c4e3 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -263,6 +263,10 @@ void getrangeCommand(client *c) { } /* Convert negative indexes */ + if (start < 0 && end < 0 && start > end) { + addReply(c,shared.emptybulk); + return; + } if (start < 0) start = strlen+start; if (end < 0) end = strlen+end; if (start < 0) start = 0;