]> git.tuebingen.mpg.de Git - osl.git/commitdiff
Fix a design flaw in osl_rbtree_loop() and osl_rbtree_loop_reverse().
authorAndre Noll <maan@systemlinux.org>
Sat, 31 May 2008 17:18:31 +0000 (19:18 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 31 May 2008 17:18:31 +0000 (19:18 +0200)
In case the loop was terminated because the user-supplied loop function
returned a negative value, the old code returned this value back to
the caller of osl_rbtree_loop(). This is bad because osl functions
should only return osl error codes.

Moreover, the return value of the loop function might coincide with an
osl error code making it impossible to distinguish between the two
errors.

The fix is to introduce a new osl error code E_OSL_LOOP which is returned
by osl_rbtree_loop() in case the loop function returned a negative value.
It's up to the caller to save any further information about the error
in the private_data struct.

osl.c

diff --git a/osl.c b/osl.c
index e1b535c563b7ae99570950f7c0152be2f3412883..81b035ddbf8c64588b350506451867a832f2a23e 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -1739,7 +1739,7 @@ __export int osl_get_row(const struct osl_table *t, unsigned col_num,
        return 1;
 }
 
        return 1;
 }
 
-static int rbtree_loop(struct osl_column *col,  void *private_data,
+static int rbtree_loop(struct osl_column *col, void *private_data,
                osl_rbtree_loop_func *func)
 {
        struct rb_node *n, *tmp;
                osl_rbtree_loop_func *func)
 {
        struct rb_node *n, *tmp;
@@ -1749,14 +1749,13 @@ static int rbtree_loop(struct osl_column *col,  void *private_data,
                        n;
                        n = tmp, tmp = tmp? rb_next(tmp) : NULL) {
                struct osl_row *r = get_row_pointer(n, col->rbtree_num);
                        n;
                        n = tmp, tmp = tmp? rb_next(tmp) : NULL) {
                struct osl_row *r = get_row_pointer(n, col->rbtree_num);
-               int ret = func(r, private_data);
-               if (ret < 0)
-                       return ret;
+               if (func(r, private_data) < 0)
+                       return -E_OSL_LOOP;
        }
        return 1;
 }
 
        }
        return 1;
 }
 
-static int rbtree_loop_reverse(struct osl_column *col,  void *private_data,
+static int rbtree_loop_reverse(struct osl_column *col, void *private_data,
                osl_rbtree_loop_func *func)
 {
        struct rb_node *n, *tmp;
                osl_rbtree_loop_func *func)
 {
        struct rb_node *n, *tmp;
@@ -1766,9 +1765,8 @@ static int rbtree_loop_reverse(struct osl_column *col,  void *private_data,
                        n;
                        n = tmp, tmp = tmp? rb_prev(tmp) : NULL) {
                struct osl_row *r = get_row_pointer(n, col->rbtree_num);
                        n;
                        n = tmp, tmp = tmp? rb_prev(tmp) : NULL) {
                struct osl_row *r = get_row_pointer(n, col->rbtree_num);
-               int ret = func(r, private_data);
-               if (ret < 0)
-                       return ret;
+               if (func(r, private_data) < 0)
+                       return -E_OSL_LOOP;
        }
        return 1;
 }
        }
        return 1;
 }
@@ -1792,7 +1790,7 @@ static int rbtree_loop_reverse(struct osl_column *col,  void *private_data,
  *
  *
  * \return Standard. If the termination of the loop was caused by \a func
  *
  *
  * \return Standard. If the termination of the loop was caused by \a func
- * returning a negative value, this value is returned.
+ * returning a negative value, \p -E_OSL_LOOP is returned.
  *
  * \sa osl_storage_flags, osl_rbtree_loop_reverse(), osl_compare_func.
  */
  *
  * \sa osl_storage_flags, osl_rbtree_loop_reverse(), osl_compare_func.
  */