Navigation Menu

Skip to content

Commit

Permalink
grn_pat: handle lr[0] == lr[1] as an error
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Oct 28, 2015
1 parent 463d848 commit 5c9e70b
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions lib/pat.c
Expand Up @@ -1186,6 +1186,11 @@ _grn_pat_del(grn_ctx *ctx, grn_pat *pat, const char *key, uint32_t key_size, int
!optarg->func(ctx, (grn_obj *)pat, r, optarg->func_arg)) {
return GRN_SUCCESS;
}
if (rn0->lr[0] == rn0->lr[1]) {
GRN_LOG(ctx, GRN_LOG_DEBUG, "*p0 (%d), rn0->lr[0] == rn0->lr[1] (%d)",
*p0, rn0->lr[0]);
return GRN_FILE_CORRUPT;
}
otherside = (rn0->lr[1] == r) ? rn0->lr[0] : rn0->lr[1];
if (otherside && r != otherside) {
PAT_AT(pat, otherside, rno);
Expand All @@ -1199,23 +1204,18 @@ _grn_pat_del(grn_ctx *ctx, grn_pat *pat, const char *key, uint32_t key_size, int
di->stat = DL_PHASE2;
di->d = r;
if (otherside) {
if (otherside == r) {
/* rn0->lr[0] == rn0->lr[1]. */
otherside = 0;
} else {
if (c0 < PAT_CHK(rno) && PAT_CHK(rno) <= c) {
/* rno is an output node and will be a non-output node. */
if (!delinfo_search(pat, otherside)) {
GRN_LOG(ctx, GRN_LOG_DEBUG, "no delinfo found %d", otherside);
}
PAT_CHK_SET(rno, 0);
}
if (proot == p0 && !rno->check) {
const uint8_t *k = pat_node_get_key(ctx, pat, rno);
int direction = k ? (*k >> 7) : 1;
rno->lr[direction] = otherside;
rno->lr[!direction] = 0;
if (c0 < PAT_CHK(rno) && PAT_CHK(rno) <= c) {
/* rno is an output node and will be a non-output node. */
if (!delinfo_search(pat, otherside)) {
GRN_LOG(ctx, GRN_LOG_DEBUG, "no delinfo found %d", otherside);
}
PAT_CHK_SET(rno, 0);
}
if (proot == p0 && !rno->check) {
const uint8_t *k = pat_node_get_key(ctx, pat, rno);
int direction = k ? (*k >> 7) : 1;
rno->lr[direction] = otherside;
rno->lr[!direction] = 0;
}
}
*p0 = otherside;
Expand Down Expand Up @@ -1284,23 +1284,18 @@ _grn_pat_del(grn_ctx *ctx, grn_pat *pat, const char *key, uint32_t key_size, int
}
} else {
if (otherside) {
if (otherside == r) {
/* rn0->lr[0] == rn0->lr[1]. */
otherside = 0;
} else {
if (c0 < PAT_CHK(rno) && PAT_CHK(rno) <= c) {
/* rno is an output node and will be a non-output node. */
if (!delinfo_search(pat, otherside)) {
GRN_LOG(ctx, GRN_LOG_ERROR, "no delinfo found %d", otherside);
}
PAT_CHK_SET(rno, 0);
}
if (proot == p0 && !rno->check) {
const uint8_t *k = pat_node_get_key(ctx, pat, rno);
int direction = k ? (*k >> 7) : 1;
rno->lr[direction] = otherside;
rno->lr[!direction] = 0;
if (c0 < PAT_CHK(rno) && PAT_CHK(rno) <= c) {
/* rno is an output node and will be a non-output node. */
if (!delinfo_search(pat, otherside)) {
GRN_LOG(ctx, GRN_LOG_ERROR, "no delinfo found %d", otherside);
}
PAT_CHK_SET(rno, 0);
}
if (proot == p0 && !rno->check) {
const uint8_t *k = pat_node_get_key(ctx, pat, rno);
int direction = k ? (*k >> 7) : 1;
rno->lr[direction] = otherside;
rno->lr[!direction] = 0;
}
}
*p0 = otherside;
Expand Down

0 comments on commit 5c9e70b

Please sign in to comment.