[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: make libxl__strdup and libxl__strndup handle NULL
commit cce28a5490c7dbeaa673f17affd1a5891c3510a4 Author: Wei Liu <wei.liu2@xxxxxxxxxx> AuthorDate: Fri Jul 17 18:01:06 2015 +0100 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Tue Jul 21 15:13:52 2015 +0100 libxl: make libxl__strdup and libxl__strndup handle NULL Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- tools/libxl/libxl_internal.c | 12 ++++++++++-- tools/libxl/libxl_internal.h | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 24a0901..23fd751 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -161,7 +161,11 @@ char *libxl__sprintf(libxl__gc *gc, const char *fmt, ...) char *libxl__strdup(libxl__gc *gc, const char *c) { - char *s = strdup(c); + char *s; + + if (!c) return NULL; + + s = strdup(c); if (!s) libxl__alloc_failed(CTX, __func__, strlen(c), 1); @@ -172,7 +176,11 @@ char *libxl__strdup(libxl__gc *gc, const char *c) char *libxl__strndup(libxl__gc *gc, const char *c, size_t n) { - char *s = strndup(c, n); + char *s; + + if (!c) return NULL; + + s = strndup(c, n); if (!s) libxl__alloc_failed(CTX, __func__, n, 1); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 3ee9fcc..3c09668 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -608,9 +608,12 @@ _hidden void *libxl__realloc(libxl__gc *gc_opt, void *ptr, size_t new_size) NN1; _hidden char *libxl__sprintf(libxl__gc *gc_opt, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3) NN1; _hidden char *libxl__vsprintf(libxl__gc *gc, const char *format, va_list ap); /* duplicate the string @c (similar to a gc'd strdup(3)). */ -_hidden char *libxl__strdup(libxl__gc *gc_opt, const char *c) NN1; +_hidden char *libxl__strdup(libxl__gc *gc_opt, + const char *c /* may be NULL */) NN1; /* duplicate at most @n bytes of string @c (similar to a gc'd strndup(3)). */ -_hidden char *libxl__strndup(libxl__gc *gc_opt, const char *c, size_t n) NN1; +_hidden char *libxl__strndup(libxl__gc *gc_opt, + const char *c /* may be NULL */, + size_t n) NN1; /* strip the last path component from @s and return as a newly allocated * string. (similar to a gc'd dirname(3)). */ _hidden char *libxl__dirname(libxl__gc *gc_opt, const char *s) NN1; -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |