Todays bug report is about newlib's snprintf() function
This example should return 0 but returns 4..
// --
#include <proto/dos.h>
#include <proto/Reactive.h>
#include <stdio.h>
int main( void )
{
TEXT buf[64];
int32 v;
buf[0] = 1;
buf[1] = 1;
buf[2] = 1;
buf[3] = 1;
v = snprintf( buf, 1, "1234" );
printf( "v %ld\n", v );
printf( "%d\n", buf[0] );
printf( "%d\n", buf[1] );
printf( "%d\n", buf[2] );
printf( "%d\n", buf[3] );
return( 0 );
}
Result looks like this
> tst.exe
v 4
0
1
1
1
Newlib bug report
- salass00
- AmigaOS Core Developer
- Posts: 530
- Joined: Sat Jun 18, 2011 3:12 pm
- Location: Finland
- Contact:
Re: Newlib bug report
No, it is correct. The snprintf() function always returns the number of characters it would have written had the buffer been large enough rather than how many characters it actually wrote. This is to allow you to easily check if the result was truncated by simply comparing the return value to the size of the buffer you used.
Re: Newlib bug report
ohh ya.. I was looking at sprintf()salass00 wrote:No, it is correct. The snprintf() function always returns the number of characters it would have written had the buffer been large enough rather than how many characters it actually wrote. This is to allow you to easily check if the result was truncated by simply comparing the return value to the size of the buffer you used.