mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
maprintf() and vmaprintf() now work better when printfing "%s" with an
empty string
This commit is contained in:
parent
2080738883
commit
c7b03d6479
@ -1028,7 +1028,6 @@ static int alloc_addbyter(int output, FILE *data)
|
|||||||
infop->len++;
|
infop->len++;
|
||||||
|
|
||||||
return output; /* fputc() returns like this on success */
|
return output; /* fputc() returns like this on success */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *curl_maprintf(const char *format, ...)
|
char *curl_maprintf(const char *format, ...)
|
||||||
@ -1044,12 +1043,17 @@ char *curl_maprintf(const char *format, ...)
|
|||||||
va_start(ap_save, format);
|
va_start(ap_save, format);
|
||||||
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
|
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
|
||||||
va_end(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 */
|
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
|
||||||
return info.buffer;
|
return info.buffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return NULL;
|
return strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *curl_mvaprintf(const char *format, va_list ap_save)
|
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;
|
info.alloc = 0;
|
||||||
|
|
||||||
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
|
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
|
||||||
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
|
if(-1 == retcode) {
|
||||||
if(info.len) {
|
if(info.alloc)
|
||||||
|
free(info.buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(info.alloc) {
|
||||||
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
|
info.buffer[info.len] = 0; /* we terminate this with a zero byte */
|
||||||
return info.buffer;
|
return info.buffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return NULL;
|
return strdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int storebuffer(int output, FILE *data)
|
static int storebuffer(int output, FILE *data)
|
||||||
|
Loading…
Reference in New Issue
Block a user