Descrepancy between Windows and GLIBC version of [v]snprintf

Daniel Gehriger gehriger at linkcad.com
Wed Nov 26 07:09:19 CST 2003


Hi,

I found a problem with the _snprintf() / _vsnprintf() functions. Wine seems
to use the forward these function calls to their native implementation (eg.
in GLIBC). The problem is that they behave differently under Windows and
GLIBC:

Both function take a parameter to specify the maximum number of characters
to write. Under Windows, if the formated string is equal in length to or
exceeds the specified number, the terminating NULL will NOT be written to
the buffer. Under Linux, the terminating NULL is ALWAYS written.

The test program below produces the following output (only when linked
dynamically, of course) :

Under Windows: 			0000000001****
Under Wine:    			000000000
When compiled on Linux:		000000000

---------------------------------------------------------
#include <stdio.h>
#include <memory.h>

int main()
{
  char buffer[16];
  memset(buffer, 0, 16);
  memset(buffer, '*', 15);

  int len = _snprintf(buffer, 10, "%010d", 1);  
  
  printf("%d : %s\n", len, buffer);
  
  return 0;
}
---------------------------------------------------------

Regards,

Daniel




More information about the wine-devel mailing list