diff --git a/src/fopenf.c b/src/fopenf.c index a56a55b..e92995f 100644 --- a/src/fopenf.c +++ b/src/fopenf.c @@ -15,6 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include #include @@ -34,7 +35,6 @@ FILE *fopenf(const char *mode, const char *fmt, ...) { va_list ap; - FILE *fp = NULL; char *file; int len; @@ -42,15 +42,17 @@ FILE *fopenf(const char *mode, const char *fmt, ...) len = vsnprintf(NULL, 0, fmt, ap); va_end(ap); - va_start(ap, fmt); file = alloca(len + 1); - if (file) { - vsnprintf(file, len + 1, fmt, ap); - fp = fopen(file, mode); + if (!file) { + errno = ENOMEM; + return NULL; } + + va_start(ap, fmt); + vsnprintf(file, len + 1, fmt, ap); va_end(ap); - return fp; + return fopen(file, mode); } /** diff --git a/src/makepath.c b/src/makepath.c index 810806e..8809653 100644 --- a/src/makepath.c +++ b/src/makepath.c @@ -70,8 +70,10 @@ int fmkpath(mode_t mode, const char *fmt, ...) va_end(ap); path = alloca(len + 1); - if (!path) + if (!path) { + errno = ENOMEM; return -1; + } va_start(ap, fmt); len = vsnprintf(path, len + 1, fmt, ap); diff --git a/src/systemf.c b/src/systemf.c index fbafe72..79ba38e 100644 --- a/src/systemf.c +++ b/src/systemf.c @@ -32,14 +32,13 @@ int systemf(const char *fmt, ...) len = vsnprintf(NULL, 0, fmt, ap); va_end(ap); - va_start(ap, fmt); cmd = alloca(++len); if (!cmd) { - va_end(ap); errno = ENOMEM; return -1; } + va_start(ap, fmt); vsnprintf(cmd, len, fmt, ap); va_end(ap);