Skip to content

Commit

Permalink
LRANGE: fixed negative stop offset behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Deltheil committed Nov 26, 2011
1 parent 9dbe70e commit d13585b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions rcli-test.sh
Expand Up @@ -139,3 +139,11 @@ rcli LRANGE mylist 0 0
rcli LRANGE mylist -3 2
rcli LRANGE mylist -100 100
rcli LRANGE mylist 5 10
rcli LRANGE mylist 0 -1
rcli LRANGE mylist 0 -2
rcli LRANGE mylist 0 -3
rcli LRANGE mylist 0 -4
rcli LRANGE mylist 1 -2
rcli LRANGE mylist 2 -1
rcli LRANGE mylist 2 -2
rcli LRANGE mylist 2 1
10 changes: 5 additions & 5 deletions tcdb.c
Expand Up @@ -489,10 +489,10 @@ rk_val_t *rk_tcdb_lrange(rk_tcdb_t *db, const char *kbuf, int ksiz,
rk_val_t *ary = NULL;
TCLIST *vals = tcbdbget4(db->lst, kbuf, ksiz);
int llen = (vals != NULL) ? tclistnum(vals) : 0;
if (llen > 0) {
if ((start < llen) && (start <= stop)) {
int low = start < 0 ? (tclmax(start, -llen) + llen) : start;
int high = stop < 0 ? (tclmax(stop, -llen) + llen) : tclmin(stop, llen-1);
if (llen > 0 && start < llen && stop >= -llen) {
int low = start < 0 ? tclmax(start, -llen) + llen : start;
int high = stop < 0 ? stop + llen : tclmin(stop, llen-1);
if (high >= low) {
int siz = high - low + 1;
ary = malloc(siz*sizeof(rk_val_t));
int i;
Expand All @@ -502,7 +502,7 @@ rk_val_t *rk_tcdb_lrange(rk_tcdb_t *db, const char *kbuf, int ksiz,
ary[i].buf = tcmemdup(vbuf, vsiz);
ary[i].siz = vsiz;
}
*num = siz;
*num = siz;
}
}
if (vals) tclistdel(vals);
Expand Down

0 comments on commit d13585b

Please sign in to comment.