]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
pair: Make fr_pair_value_snprintf use our interanl fr_vasprintf function via the...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 23 May 2020 16:34:37 +0000 (11:34 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 23 May 2020 16:34:37 +0000 (11:34 -0500)
src/lib/util/pair.c
src/lib/util/pair.h

index 96a973de5873ba6fe08f0906858396d03defbb42..ff72b00d715bc9576a85fd52d1e7dd9dfe657ab6 100644 (file)
@@ -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
index 735e252d49f09eb6b84a4449c9548cff88380909..a23326d4f90c5c9a0ba89e620997d3425f5ea80a 100644 (file)
@@ -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);