This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with snprintf()


Doug Wyatt wrote:
> Is the newlib version wrong?  It appears to be in light of this
> excerpt from the RH6.2 snprintf man entry, also:
> 
>   Return value
>   "
>   "
>   snprintf and  vsnprintf  do  not write  more than size bytes
>   (including the trailing '\0'), and return -1 if the output was
>   truncated due to this limit.  (Thus until glibc 2.0.6.  Since
>   glibc 2.1 these functions follow the C99 standard and return the
>   number of characters (excluding the trailing '\0') which would
>   have been written to the final string if enough space had been
>   available.)
> 
> The problem arises in a configure file which wants (size - 1)
> bytes in 'target'.
> 
> Is the newlib behavior a variant or a bug?

I have found another problem with snprintf. While porting OpenSSH
to Cygwin I found that configure reports the following:

configure:2567: checking whether snprintf correctly terminates long
                strings
configure:      warning: ****** Your snprintf() function is broken,
                complain to your vendor

The configure file contains the following test:

#include <stdio.h>
int main(void){char b[5];snprintf(b,5,"123456789");return(b[4]!='\0');}


As you can see, it expects snprintf terminating strings with \0 always
which seems not to be the case for the newlib version.

Shouldn't this be fixed as well?

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                        mailto:cygwin@sources.redhat.com
Red Hat, Inc.
mailto:vinschen@cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]