mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
util: add virVasprintf
* src/util/util.h (virVasprintf): New declaration. * src/util/util.c (virVasprintf): New function. (virAsprintf): Use it. * src/util/virtaudit.c (virAuditSend): Likewise. * src/libvirt_private.syms: Export it. * cfg.mk (sc_prohibit_asprintf): Also prohibit vasprintf. * .x-sc_prohibit_asprintf: Add exemption.
This commit is contained in:
parent
dbab6bb5cf
commit
fce3baee26
@ -1,3 +1,5 @@
|
|||||||
|
ChangeLog
|
||||||
|
^bootstrap.conf$
|
||||||
^gnulib/
|
^gnulib/
|
||||||
^po/
|
^po/
|
||||||
ChangeLog
|
^src/util/util.c$
|
||||||
|
2
cfg.mk
2
cfg.mk
@ -255,7 +255,7 @@ sc_prohibit_strncmp:
|
|||||||
|
|
||||||
# Use virAsprintf rather than as'printf since *strp is undefined on error.
|
# Use virAsprintf rather than as'printf since *strp is undefined on error.
|
||||||
sc_prohibit_asprintf:
|
sc_prohibit_asprintf:
|
||||||
@prohibit='\<a[s]printf\>' \
|
@prohibit='\<v?a[s]printf\>' \
|
||||||
halt='use virAsprintf, not as'printf \
|
halt='use virAsprintf, not as'printf \
|
||||||
$(_sc_search_regexp)
|
$(_sc_search_regexp)
|
||||||
|
|
||||||
|
@ -817,6 +817,7 @@ virStrToLong_ull;
|
|||||||
virStrcpy;
|
virStrcpy;
|
||||||
virStrncpy;
|
virStrncpy;
|
||||||
virTimestamp;
|
virTimestamp;
|
||||||
|
virVasprintf;
|
||||||
|
|
||||||
|
|
||||||
# uuid.h
|
# uuid.h
|
||||||
|
@ -2198,6 +2198,22 @@ virParseVersionString(const char *str, unsigned long *version)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virVasprintf
|
||||||
|
*
|
||||||
|
* like glibc's vasprintf but makes sure *strp == NULL on failure
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virVasprintf(char **strp, const char *fmt, va_list list)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if ((ret = vasprintf(strp, fmt, list)) == -1)
|
||||||
|
*strp = NULL;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virAsprintf
|
* virAsprintf
|
||||||
*
|
*
|
||||||
@ -2210,10 +2226,7 @@ virAsprintf(char **strp, const char *fmt, ...)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
ret = virVasprintf(strp, fmt, ap);
|
||||||
if ((ret = vasprintf(strp, fmt, ap)) == -1)
|
|
||||||
*strp = NULL;
|
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <sys/select.h>
|
# include <sys/select.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
# ifndef MIN
|
# ifndef MIN
|
||||||
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
@ -202,7 +203,10 @@ int virMacAddrCompare (const char *mac1, const char *mac2);
|
|||||||
void virSkipSpaces(const char **str);
|
void virSkipSpaces(const char **str);
|
||||||
int virParseNumber(const char **str);
|
int virParseNumber(const char **str);
|
||||||
int virParseVersionString(const char *str, unsigned long *version);
|
int virParseVersionString(const char *str, unsigned long *version);
|
||||||
int virAsprintf(char **strp, const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(2, 3);
|
int virAsprintf(char **strp, const char *fmt, ...)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3);
|
||||||
|
int virVasprintf(char **strp, const char *fmt, va_list list)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 0);
|
||||||
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
||||||
ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
||||||
|
@ -95,7 +95,7 @@ void virAuditSend(const char *file ATTRIBUTE_UNUSED, const char *func,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
if (vasprintf(&str, fmt, args) < 0) {
|
if (virVasprintf(&str, fmt, args) < 0) {
|
||||||
VIR_WARN0("Out of memory while formatting audit message");
|
VIR_WARN0("Out of memory while formatting audit message");
|
||||||
str = NULL;
|
str = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user