Problem with snprintf()

Egor Duda
Mon Aug 7 09:12:00 GMT 2000


Monday, 07 August, 2000 Corinna Vinschen 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?

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

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

CV> The configure file contains the following test:

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

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

CV> Shouldn't this be fixed as well?

Susv2  is not very informative on this subject. Does anybody have ANSI
standard to make snprintf ANSI-compliant ?

Egor.   ICQ 5165414 FidoNet 2:5020/496.19

More information about the Newlib mailing list