From: Arran Cudbard-Bell Date: Sat, 23 May 2020 16:34:37 +0000 (-0500) Subject: pair: Make fr_pair_value_snprintf use our interanl fr_vasprintf function via the... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5ce016c81e6ce98f84fe254bbbc71eb04608c0e;p=thirdparty%2Ffreeradius-server.git pair: Make fr_pair_value_snprintf use our interanl fr_vasprintf function via the value box API --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 96a973de587..ff72b00d715 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -1670,28 +1670,25 @@ void fr_pair_value_bstrnsteal(VALUE_PAIR *vp, char *src, size_t len) * @param[in,out] vp to update * @param[in] fmt the format string */ -void fr_pair_value_snprintf(VALUE_PAIR *vp, char const *fmt, ...) +int fr_pair_value_snprintf(VALUE_PAIR *vp, char const *fmt, ...) { - va_list ap; - char *p; + int ret; + va_list ap; - if (!fr_cond_assert(vp->da->type == FR_TYPE_STRING)) return; + if (!fr_cond_assert(vp->da->type == FR_TYPE_STRING)) return -1; + fr_value_box_clear(&vp->data); va_start(ap, fmt); - p = talloc_vasprintf(vp, fmt, ap); + ret = fr_value_box_vasprintf(vp, &vp->data, vp->da, false, fmt, ap); va_end(ap); - if (!p) return; - fr_value_box_clear(&vp->data); - - vp->vp_strvalue = p; - vp->vp_length = talloc_array_length(vp->vp_strvalue) - 1; - vp->vp_type = FR_TYPE_STRING; - talloc_set_type(vp->vp_ptr, char); - - vp->type = VT_DATA; + if (ret == 0) { + vp->type = VT_DATA; + VP_VERIFY(vp); + return 0; + } - VP_VERIFY(vp); + return -1; } /** Print the value of an attribute to a string diff --git a/src/lib/util/pair.h b/src/lib/util/pair.h index 735e252d49f..a23326d4f90 100644 --- a/src/lib/util/pair.h +++ b/src/lib/util/pair.h @@ -337,7 +337,7 @@ void fr_pair_value_strsteal(VALUE_PAIR *vp, char const *src); void fr_pair_value_strcpy(VALUE_PAIR *vp, char const *src); void fr_pair_value_bstrncpy(VALUE_PAIR *vp, void const *src, size_t len); void fr_pair_value_bstrnsteal(VALUE_PAIR *vp, char *src, size_t len); -void fr_pair_value_snprintf(VALUE_PAIR *vp, char const *fmt, ...) CC_HINT(format (printf, 2, 3)); +int fr_pair_value_snprintf(VALUE_PAIR *vp, char const *fmt, ...) CC_HINT(format (printf, 2, 3)); /* Printing functions */ size_t fr_pair_value_snprint(char *out, size_t outlen, VALUE_PAIR const *vp, char quote);