Navigation Menu

Skip to content

Commit

Permalink
fix a bug in grn_table_sort with offset and limit options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryo Onodera committed Oct 7, 2009
1 parent fd84a48 commit 7fb4f96
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/db.c
Expand Up @@ -5620,7 +5620,7 @@ int
grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
grn_obj *result, grn_table_sort_key *keys, int n_keys)
{
int n, r, i = 0;
int n, e, i = 0;
sort_entry *array, *ep;
GRN_API_ENTER;
if (!n_keys || !keys) {
Expand All @@ -5645,12 +5645,12 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
if (offset < 0) { offset = 0; }
}
if (offset >= n) { goto exit; }
r = n - offset;
if (limit < 0) {
limit += r + 1;
limit += n + 1;
}
if (limit <= 0) { goto exit; }
if (limit > r) { limit = r; }
e = limit + offset;
if (e <= 0) { goto exit; }
if (e > n) { e = n; }
{
int j;
grn_table_sort_key *kp;
Expand Down Expand Up @@ -5725,15 +5725,15 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
goto exit;
}
if ((ep = pack(ctx, table, array, array + n - 1, keys, n_keys))) {
intptr_t rest = limit - 1 - (ep - array);
_sort(ctx, array, ep - 1, limit, keys, n_keys);
intptr_t rest = e - 1 - (ep - array);
_sort(ctx, array, ep - 1, e, keys, n_keys);
if (rest > 0 ) {
_sort(ctx, ep + 1, array + n - 1, (int)rest, keys, n_keys);
}
}
{
grn_id *v;
for (i = 0, ep = array + offset; i < limit; i++, ep++) {
for (i = 0, ep = array + offset; i < limit && ep < array + n; i++, ep++) {
if (!grn_array_add(ctx, (grn_array *)result, (void **)&v)) { break; }
if (!(*v = ep->id)) { break; }
}
Expand Down

0 comments on commit 7fb4f96

Please sign in to comment.