From 83ac9cd518766c5db25bc3cdb34ee276c89770ee Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 12 Jul 2007 23:35:09 +0000 Subject: [PATCH] Create and use xasprintf akin to xmalloc, returns pointer on success or exits on error git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19708 dc483132-0cff-0310-8789-dd5450dbe970 --- src/clients/ksu/authorization.c | 6 +----- src/clients/ksu/xmalloc.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/clients/ksu/authorization.c b/src/clients/ksu/authorization.c index 09a67b976..b5713c103 100644 --- a/src/clients/ksu/authorization.c +++ b/src/clients/ksu/authorization.c @@ -349,7 +349,6 @@ krb5_boolean fcmd_resolve(fcmd, out_fcmd, out_err) char ***out_fcmd; char **out_err; { - char * out_path; char * err; char ** tmp_fcmd; char * path_ptr, *path; @@ -402,10 +401,7 @@ krb5_boolean fcmd_resolve(fcmd, out_fcmd, out_err) return FALSE; } - out_path = (char *) xmalloc(strlen(tc) + strlen(fcmd) + 2); - sprintf(out_path,"%s/%s",tc, fcmd ); - - tmp_fcmd[i] = out_path; + tmp_fcmd[i] = xasprintf("%s/%s", tc, fcmd); i++; diff --git a/src/clients/ksu/xmalloc.c b/src/clients/ksu/xmalloc.c index 425b44f0e..44bdca16d 100644 --- a/src/clients/ksu/xmalloc.c +++ b/src/clients/ksu/xmalloc.c @@ -28,6 +28,8 @@ */ #include "ksu.h" +#include +#include "k5-platform.h" void *xmalloc (size_t sz) { @@ -66,3 +68,17 @@ char *xstrdup (const char *src) memcpy (dst, src, len); return dst; } + +char *xasprintf (const char *format, ...) +{ + char *out; + va_list args; + + va_start (args, format); + if (vasprintf(&out, format, args) < 0) { + perror (prog_name); + exit (1); + } + va_end(args); + return out; +} -- 2.26.2