From: Arran Cudbard-Bell Date: Thu, 2 Apr 2020 16:34:31 +0000 (-0600) Subject: cursor: Add note and guard for fr_cursor_intersect_* functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b12940a1ae6ba22f7836c4e4e4b0b2d00325f9ef;p=thirdparty%2Ffreeradius-server.git cursor: Add note and guard for fr_cursor_intersect_* functions --- diff --git a/src/lib/util/cursor.c b/src/lib/util/cursor.c index 5be7d695a50..585c2ec777d 100644 --- a/src/lib/util/cursor.c +++ b/src/lib/util/cursor.c @@ -403,6 +403,8 @@ void fr_cursor_merge(fr_cursor_t *cursor, fr_cursor_t *to_append) } /** Return the first item matching the iterator in cursor a and cursor b + * + * @note Both cursors must operate on the same list of items. * * @param[in] a First cursor. * @param[in] b Second cursor. @@ -412,6 +414,8 @@ void *fr_cursor_intersect_head(fr_cursor_t *a, fr_cursor_t *b) { void *a_item, *b_item; + if (unlikely(a->head != b->head)) return NULL; + a_item = fr_cursor_head(a); b_item = fr_cursor_head(b); @@ -421,6 +425,8 @@ void *fr_cursor_intersect_head(fr_cursor_t *a, fr_cursor_t *b) } /** Return the next item matching the iterator in cursor a and cursor b + * + * @note Both cursors must operate on the same list of items. * * @param[in] a First cursor. * @param[in] b Second cursor. @@ -430,6 +436,8 @@ void *fr_cursor_intersect_next(fr_cursor_t *a, fr_cursor_t *b) { fr_cursor_iter_t b_iter; + if (unlikely(a->head != b->head)) return NULL; + /* * If either of the iterators lack an iterator * just use cursor_next...