]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add yet another typed talloc function
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 4 Jul 2017 22:50:38 +0000 (18:50 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 4 Jul 2017 22:50:38 +0000 (18:50 -0400)
src/include/talloc.h
src/lib/util/talloc.c

index dec34a9bab1ba48d8fde19e1893bba85c65ed807..8a9bc214a36a51d0e11650d7c91b6fcb54b5c290 100644 (file)
@@ -27,6 +27,8 @@ char          *talloc_typed_strdup(void const *t, char const *p);
 
 char           *talloc_typed_asprintf(void const *t, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
 
+char           *talloc_typed_vasprintf(void const *t, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0)) CC_HINT(nonnull (2));
+
 char           *talloc_bstrndup(void const *t, char const *in, size_t inlen);
 
 int            talloc_memcmp_array(uint8_t const *a, uint8_t const *b);
index 23e77311f0499a61aefe94f218417031b8257db4..e7248dd3750f7f94779357e277df187ad0366d1f 100644 (file)
@@ -95,6 +95,30 @@ char *talloc_typed_asprintf(void const *t, char const *fmt, ...)
        return n;
 }
 
+/** Call talloc vasprintf, setting the type on the new chunk correctly
+ *
+ * For some bizarre reason the talloc string functions don't set the
+ * memory chunk type to char, which causes all kinds of issues with
+ * verifying VALUE_PAIRs.
+ *
+ * @param[in] t The talloc context to hang the result off.
+ * @param[in] fmt The format string.
+ * @return
+ *     - Formatted string.
+ *     - NULL on error.
+ */
+char *talloc_typed_vasprintf(void const *t, char const *fmt, va_list ap)
+{
+       char *n;
+
+       n = talloc_vasprintf(t, fmt, ap);
+       if (!n) return NULL;
+       talloc_set_type(n, char);
+
+       return n;
+}
+
+
 /** Binary safe strndup function
  *
  * @param[in] t The talloc context o allocate new buffer in.