PATCH: tools/winegcc/utils.c -- casts

Ferenc Wagner wferi at afavant.elte.hu
Thu Oct 30 18:28:49 CST 2003


Gerald Pfeifer <gerald at pfeifer.com> writes:

> Add proper casts to avoid signed vs. unsigned mismatches in strmake().

> -        if (n > -1 && n < size) return p;
> -	size = min( size*2, n+1 );
> +        if (n > -1 && (size_t)n < size) return p;
> +	size = min( size*2, (size_t)n+1 );

Once at it, could you please explain to me what the hell is
going on here (min)?  I came across this function recently,
and do not agree with its logic.  I would write it like

char *strmake(const char *fmt, ...)
{
    int n;
    size_t size = 100;
    char *p = xmalloc (size+1);
    va_list ap;

    va_start (ap, fmt);
    n = vsnprintf (p, size, fmt, ap);
    while (n < 0) {
        size *= 2;
        p = xrealloc (p, size+1);
        n = vsnprintf (p, size, fmt, ap);
    }
    if ((size_t)n == size) p[size]=0;
    va_end (ap);
    return p;
}

By the way, either Wine's snprintf implementation is wrong
or I do not know how to use it correctly.  I am submitting a
conformance test...

-- 
Feri.



More information about the wine-devel mailing list