Skip to content

Commit

Permalink
CID 1411534: Replace at the end of the cusor becomes append
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 30, 2017
1 parent a710e5b commit a24054e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/util/cursor.c
Expand Up @@ -452,18 +452,27 @@ void * CC_HINT(hot) fr_cursor_replace(fr_cursor_t *cursor, void *r)
return NULL;
}

/*
* If there's a head, but no current,
* we've iterated off the end of the list,
* so the replace becomes an append.
*/
v = cursor->current;
if (v) {
fr_cursor_append(cursor, r);
return NULL;
}
p = cursor->prev;

/*
* Item at the head of the list.
*/
if (*cursor->head == v) {
*cursor->head = r;
if (v) *NEXT_PTR(r) = *NEXT_PTR(v);
*NEXT_PTR(r) = *NEXT_PTR(v);
} else {
*NEXT_PTR(p) = r;
if (v) *NEXT_PTR(r) = *NEXT_PTR(v);
*NEXT_PTR(r) = *NEXT_PTR(v);
}

/*
Expand Down

0 comments on commit a24054e

Please sign in to comment.