char *buffer; /* allocated buffer */
size_t len; /* length of string */
size_t alloc; /* length of alloc */
+ bool fail; /* TRUE if an alloc has failed and thus the output is not
+ the complete data */
};
int curl_msprintf(char *buffer, const char *format, ...);
if(!infop->buffer) {
infop->buffer=(char *)malloc(32);
- if(!infop->buffer)
+ if(!infop->buffer) {
+ infop->fail = TRUE;
return -1; /* fail */
+ }
infop->alloc = 32;
infop->len =0;
}
newptr = (char *)realloc(infop->buffer, infop->alloc*2);
if(!newptr) {
+ infop->fail = TRUE;
return -1;
}
infop->buffer = newptr;
info.buffer = NULL;
info.len = 0;
info.alloc = 0;
+ info.fail = FALSE;
va_start(ap_save, format);
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
va_end(ap_save);
- if(-1 == retcode) {
+ if((-1 == retcode) || info.fail) {
if(info.alloc)
free(info.buffer);
return NULL;
info.buffer = NULL;
info.len = 0;
info.alloc = 0;
+ info.fail = FALSE;
retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
- if(-1 == retcode) {
+ if((-1 == retcode) || info.fail) {
if(info.alloc)
free(info.buffer);
return NULL;