Convert one cast call to value_data_cast
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 31 Oct 2014 00:45:40 +0000 (20:45 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 31 Oct 2014 16:56:22 +0000 (12:56 -0400)
src/main/evaluate.c

index 1c61b68..9727d91 100644 (file)
@@ -530,7 +530,9 @@ int radius_evaluate_map(REQUEST *request, UNUSED int modreturn, UNUSED int depth
         *      They're both attributes.  Do attribute-specific work.
         */
        if (!c->cast && (map->lhs->type == TMPL_TYPE_ATTR) && (map->rhs->type == TMPL_TYPE_ATTR)) {
-               VALUE_PAIR *lhs_vp, *rhs_vp, *cast_vp;
+               VALUE_PAIR *lhs_vp, *rhs_vp;
+               ssize_t ret;
+               value_data_t cast_data;
 
                EVAL_DEBUG("ATTR to ATTR");
                if ((tmpl_find_vp(&lhs_vp, request, map->lhs) < 0) ||
@@ -551,19 +553,17 @@ int radius_evaluate_map(REQUEST *request, UNUSED int modreturn, UNUSED int depth
                           (map->rhs->tmpl_da->type == PW_TYPE_SHORT) ||
                           (map->rhs->tmpl_da->type == PW_TYPE_BYTE));
 
-               cast_vp = pairalloc(request, lhs_vp->da);
-               if (!cast_vp) return false;
+               ret = value_data_cast(rhs_vp, &cast_data,
+                                     lhs_vp->da->type, lhs_vp->da,
+                                     rhs_vp->da->type, rhs_vp->da,
+                                     &rhs_vp->data, rhs_vp->length);
+               if (ret < 0) return -1;
 
-               /*
-                *      Copy the RHS to the casted type.
-                */
-               if (do_cast_copy(cast_vp, rhs_vp) < 0) {
-                       talloc_free(cast_vp);
-                       return false;
-               }
+               rcode = value_data_cmp_op(map->op,
+                                         lhs_vp->da->type, &lhs_vp->data, lhs_vp->length,
+                                         lhs_vp->da->type, &cast_data, (size_t)ret);
+               if (lhs_vp->da->flags.is_pointer) talloc_free(cast_data.ptr);
 
-               rcode = paircmp_op(map->op, lhs_vp, cast_vp);
-               talloc_free(cast_vp);
                return rcode;
        }