diff --git a/src/bitops.c b/src/bitops.c index fa21f08172..035840287f 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -818,9 +818,6 @@ void bitcountCommand(client *c) { if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK) return; } - else if (c->argc < 4) { - end = totlen-1; - } /* Lookup, check for type. */ o = lookupKeyRead(c->db, c->argv[1]); @@ -831,13 +828,14 @@ void bitcountCommand(client *c) { /* Make sure we will not overflow */ serverAssert(totlen <= LLONG_MAX >> 3); + if (c->argc < 4) end = totlen-1; + /* Convert negative indexes */ if (start < 0 && end < 0 && start > end) { addReply(c,shared.czero); return; } if (isbit) totlen <<= 3; - /* Convert negative indexes */ if (start < 0) start = totlen+start; if (end < 0) end = totlen+end; if (start < 0) start = 0; @@ -928,9 +926,6 @@ void bitposCommand(client *c) { return; end_given = 1; } - else if (c->argc < 5) { - end = totlen-1; - } /* Lookup, check for type. */ o = lookupKeyRead(c->db, c->argv[1]); @@ -941,6 +936,8 @@ void bitposCommand(client *c) { long long totlen = strlen; serverAssert(totlen <= LLONG_MAX >> 3); + if (c->argc < 5) end = totlen-1; + if (isbit) totlen <<= 3; /* Convert negative indexes */ if (start < 0) start = totlen+start;