[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    Re: PATCH: tools/winegcc/utils.c -- casts
From:       Ferenc Wagner <wferi () afavant ! elte ! hu>
Date:       2003-10-31 0:28:49
[Download RAW message or body]

Gerald Pfeifer <gerald@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.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic