[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good bits from Marcin's patch3

From: BORBELY Zoltan
Subject: Re: Good bits from Marcin's patch3
Date: Wed, 3 Apr 2002 16:15:21 +0200
User-agent: Mutt/


On Wed, Apr 03, 2002 at 02:02:55PM +0100, Ian Campbell wrote:
> > What kind of *nix are you using? Maybe we should check for _broken_ snprintf
> > implementation too...
> Just to stick my oar in, but perhaps this would be useful...

It's not enough. It just checks wheter snprintf(NULL, 0, ...) can be
accepted. C99 implementations will return the required buffer size - 1
(not counting the terminating \0 character).

We should implement another test, similar to the following (just an idea,
I'll finish it this night):

    char buf[5] = {0, 0, 0, 0, 0};
    snprintf(buf, 4, "ABCD");
    exit( strlen(buf) != 3 );

If the implementation is broken strlen(buf) will be 4, C99 compliant should
produce 3. :-)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]