* @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
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);