# define mp_uintmax_t unsigned long
#endif
-#define BUFFSIZE 326 /* buffer for long-to-str and float-to-str calcs, should
- fit negative DBL_MAX (317 letters) */
+#define BUFFSIZE 256 /* buffer for long-to-str and float-to-str calcs */
#define MAX_PARAMETERS 128 /* lame static limit */
#ifdef __AMIGA__
* Create an index with the type of each parameter entry and its
* value (may vary in size)
*
- * Returns zero on success.
- *
******************************************************************/
-static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
- va_list arglist)
+static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
+ va_list arglist)
{
char *fmt = (char *)format;
int param_num = 0;
flags |= FLAGS_ALT;
break;
case '.':
+ flags |= FLAGS_PREC;
if('*' == *fmt) {
/* The precision is picked from a specified parameter */
i = this_param - 1;
- if((i < 0) || (i >= MAX_PARAMETERS))
- /* out of allowed range */
- return 1;
-
switch (*fmt) {
case 'S':
flags |= FLAGS_ALT;
(mp_intmax_t)va_arg(arglist, int);
}
- switch(vto[i].type) {
+ switch (vto[i].type) {
case FORMAT_STRING:
vto[i].data.str = va_arg(arglist, char *);
break;
}
}
- return 0;
+ return max_param;
}
char *workend = &work[sizeof(work) - 2];
/* Do the actual %-code parsing */
- if(dprintf_Pass1(format, vto, endpos, ap_save))
- return -1;
+ dprintf_Pass1(format, vto, endpos, ap_save);
end = &endpos[0]; /* the initial end-position from the list dprintf_Pass1()
created for us */
is_alt = (p->flags & FLAGS_ALT) ? 1 : 0;
- switch(p->type) {
+ switch (p->type) {
case FORMAT_INT:
num = p->data.num.as_unsigned;
if(p->flags & FLAGS_CHAR) {
*fptr = 0;
if(width >= 0) {
- if(width >= (long)sizeof(work))
- width = sizeof(work)-1;
/* RECURSIVE USAGE */
len = curl_msnprintf(fptr, left, "%ld", width);
fptr += len;
left -= len;
}
if(prec >= 0) {
- /* for each digit in the integer part, we can have one less
- precision */
- size_t maxprec = sizeof(work) - 2;
- double val = p->data.dnum;
- while(val >= 10.0) {
- val /= 10;
- maxprec--;
- }
-
- if(prec > (long)maxprec)
- prec = (long)maxprec-1;
/* RECURSIVE USAGE */
len = curl_msnprintf(fptr, left, ".%ld", prec);
fptr += len;
/* NOTE NOTE NOTE!! Not all sprintf implementations return number of
output characters */
(sprintf)(work, formatbuf, p->data.dnum);
-#ifdef CURLDEBUG
- assert(strlen(work) <= sizeof(work));
-#endif
+
for(fptr=work; *fptr; fptr++)
OUTCHAR(*fptr);
}
info.max = maxlength;
retcode = dprintf_formatf(&info, addbyter, format, ap_save);
- if((retcode != -1) && info.max) {
+ if(info.max) {
/* we terminate this with a zero byte */
if(info.max == info.length)
/* we're at maximum, scrap the last letter */
infop->len =0;
}
else if(infop->len+1 >= infop->alloc) {
- char *newptr = NULL;
- size_t newsize = infop->alloc*2;
+ char *newptr;
- /* detect wrap-around or other overflow problems */
- if(newsize > infop->alloc)
- newptr = realloc(infop->buffer, newsize);
+ newptr = realloc(infop->buffer, infop->alloc*2);
if(!newptr) {
infop->fail = 1;
return -1; /* fail */
}
infop->buffer = newptr;
- infop->alloc = newsize;
+ infop->alloc *= 2;
}
infop->buffer[ infop->len ] = outc;