Discussion:
vsnprintf doesn't work anymore?
(too old to reply)
J
2012-11-17 01:40:01 UTC
Permalink
I'm pretty sure that it used to work the same as GCC's version...

vsnprintf( NULL, 0, "...", ... );

should return the number of characters that the result string would be...,
not -1.

same for just snprintf
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
J
2012-11-17 01:41:35 UTC
Permalink
Post by J
I'm pretty sure that it used to work the same as GCC's version...
vsnprintf( NULL, 0, "...", ... );
should return the number of characters that the result string would
be..., not -1.
same for just snprintf
hmm maybe it does... I'm actually using vsnwprintf now... so maybe
vsnwprintf and snwprintf are what's broken. I'll do some test cases later.
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
J
2012-11-17 08:25:05 UTC
Permalink
----------- main.c -----------
#include <stdio.h>
#include <stdlib.h>

int main( void )
{
printf( "%d\n",
snprintf( NULL, 0, "blah %d", 1234 ) );
printf( "%d\n",
_snwprintf( NULL, 0, L"blah %d", 1234 ) );
}
---------- end main.c ----------

output:
9
-1

Expected output:
9
9
Post by J
Post by J
I'm pretty sure that it used to work the same as GCC's version...
vsnprintf( NULL, 0, "...", ... );
should return the number of characters that the result string would
be..., not -1.
same for just snprintf
hmm maybe it does... I'm actually using vsnwprintf now... so maybe
vsnwprintf and snwprintf are what's broken. I'll do some test cases later.
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
Johann Klammer
2012-11-18 04:34:29 UTC
Permalink
Post by J
----------- main.c -----------
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
printf( "%d\n",
snprintf( NULL, 0, "blah %d", 1234 ) );
printf( "%d\n",
_snwprintf( NULL, 0, L"blah %d", 1234 ) );
}
---------- end main.c ----------
9
-1
9
9
man snprintf on a linux system says(in the NOTES paragraph):

<quote>
The glibc implementation of the functions snprintf() and vsnprintf()
conforms to the C99 standard, that is, behaves as described above,
since glibc version 2.1. Until glibc 2.0.6 they would return -1 when
the output was truncated.
</quote>

watcom seems just a little behind...
(Yes, it is a bug. The C201x draft says that it's supposed to return the
number of wide chars that would have been written...)
Marty Stanquist
2012-11-24 06:07:59 UTC
Permalink
Were you able to find a workaround? We'll eventually be addressing C99
issues but I'm not sure exactly when.

Marty
Post by J
----------- main.c -----------
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
printf( "%d\n",
snprintf( NULL, 0, "blah %d", 1234 ) );
printf( "%d\n",
_snwprintf( NULL, 0, L"blah %d", 1234 ) );
}
---------- end main.c ----------
9
-1
9
9
man snprintf on a linux system says(in the NOTES paragraph):

<quote>
The glibc implementation of the functions snprintf() and vsnprintf()
conforms to the C99 standard, that is, behaves as described above,
since glibc version 2.1. Until glibc 2.0.6 they would return -1 when
the output was truncated.
</quote>

watcom seems just a little behind...
(Yes, it is a bug. The C201x draft says that it's supposed to return the
number of wide chars that would have been written...)
J
2012-11-28 01:17:42 UTC
Permalink
Post by Marty Stanquist
Were you able to find a workaround? We'll eventually be addressing C99
issues but I'm not sure exactly when.
At this point, I do not have a workaround. What I can maybe do is to
iteratively extend the buffer until it stops returning -1... but I just
stopped testing that particular build mode for now. Visual studio says to
use their strsafe.h ( sort of...
http://msdn.microsoft.com/en-us/library/ms859600.aspx ) ... but all of
those functions are no good for measuring how long the buffer is before
it's used, so those are also useless.
Post by Marty Stanquist
Marty
Post by J
----------- main.c -----------
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
printf( "%d\n",
snprintf( NULL, 0, "blah %d", 1234 ) );
printf( "%d\n",
_snwprintf( NULL, 0, L"blah %d", 1234 ) );
}
---------- end main.c ----------
9
-1
9
9
<quote>
The glibc implementation of the functions snprintf() and vsnprintf()
conforms to the C99 standard, that is, behaves as described above,
since glibc version 2.1. Until glibc 2.0.6 they would return -1 when
the output was truncated.
</quote>
watcom seems just a little behind...
(Yes, it is a bug. The C201x draft says that it's supposed to return the
number of wide chars that would have been written...)
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
Loading...