aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-05-21 17:59:57 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-05-21 17:59:57 +0000
commitc7b03d6479f59ca3330ebc0794c0e9f4fdb5aaea (patch)
tree608e4c2832f106a2b3490f1c9f7927f1dd5152ce
parent20807388837d5ccafdff5680ba400ceadd7600fc (diff)
maprintf() and vmaprintf() now work better when printfing "%s" with an
empty string
-rw-r--r--lib/mprintf.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/mprintf.c b/lib/mprintf.c
index 37332b2ce..1a908b3f2 100644
--- a/lib/mprintf.c
+++ b/lib/mprintf.c
@@ -1028,7 +1028,6 @@ static int alloc_addbyter(int output, FILE *data)
infop->len++;
return output; /* fputc() returns like this on success */
-
}
char *curl_maprintf(const char *format, ...)
@@ -1044,12 +1043,17 @@ char *curl_maprintf(const char *format, ...)
va_start(ap_save, format);
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
va_end(ap_save);
- if(info.len) {
+ if(-1 == retcode) {
+ if(info.alloc)
+ free(info.buffer);
+ return NULL;
+ }
+ if(info.alloc) {
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
return info.buffer;
}
else
- return NULL;
+ return strdup("");
}
char *curl_mvaprintf(const char *format, va_list ap_save)
@@ -1062,13 +1066,18 @@ char *curl_mvaprintf(const char *format, va_list ap_save)
info.alloc = 0;
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
- info.buffer[info.len] = 0; /* we terminate this with a zero byte */
- if(info.len) {
+ if(-1 == retcode) {
+ if(info.alloc)
+ free(info.buffer);
+ return NULL;
+ }
+
+ if(info.alloc) {
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
return info.buffer;
}
else
- return NULL;
+ return strdup("");
}
static int storebuffer(int output, FILE *data)