On 2013/8/1 8:58, Luis Lavena wrote:
> Hello folks,
>
> As maintainer of RubyInstaller (binary distribution of Ruby on Windows), we 
> opted to use Ruben's mingw-w64 binary packages as compiler toolchain and also 
> as
> part of our DevKit, to allow users install and compile extensions to the 
> language.
>
> A few days ago, a user reported an interesting case that shows issues with 
> snprintf:
>
> https://github.com/oneclick/rubyinstaller/issues/186
>
> The test case is simple, the following script:
>
> #include <stdio.h>
> #include <string.h>
> #include <assert.h>
>
> char small_buffer[10];
> char *small_text = "123";
> char *big_text = "12345678901234567890";
>
> int main(int argc, char *argv[])
> {
>   int rc;
>
>   // Text fits into buffer: snprintf returns length. 
>   rc = snprintf(small_buffer, sizeof(small_buffer), small_text);
>   printf("small_text rc = %d\n", rc);
>   assert(rc == strlen(small_text));
>
>   // Text too big for buffer: ANSI C99 snprintf should return required length.
>   // Gnu/Linux follows ANSI C99.
>   // MinGW is supposed to follow ANSI C99.
>   // Windows is broken and fails this test.
>   rc = snprintf(small_buffer, sizeof(small_buffer), big_text);
>   printf("big_text rc = %d\n", rc);
>   assert(rc > 0);
>
>   return(0);
> }
>
>
> Compiled with mingw 4.7.2 (std=c99 or ANSI), this is the output:
>
> C:\Users\Luis\Code\_sandbox\scripts>gcc --version
> gcc (GCC) 4.7.2
>
> C:\Users\Luis\Code\_sandbox\scripts>test-472-mingw.exe
> small_text rc = 3
> big_text rc = 20
>
> While either Ruben's or mingw-builds resulted in:
>
> C:\Users\Luis\Code\_sandbox\scripts>test-472-32.exe
> small_text rc = 3
> big_text rc = -1
> Assertion failed!
>
> Program: C:\Users\Luis\Code\_sandbox\scripts\test-472-32.exe
> File: test.snprintf.c, Line 24
>
> Expression: rc > 0
>
> Tested against:
>
> Ruben's 4.7.2 (packages):
> i686-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z
> i686_64-w64-mingw32-mingw-w64-update-v2.0.7_rubenvb.7z
>
> mingw-builds 4.7.3 (packages):
> x32-4.7.3-release-win32-sjlj-rev1.7z
>
> Definitely I'm missing something here, so will appreciate any hint and 
> suggestion.
>
> Thank you in advance.
> -- 
> Luis Lavena
> AREA 17
> -

This is expected. You must define __USE_MINGW_ANSI_STDIO or _POSIX yourself.
Here is the test case:

C:\var\building>gcc --version
gcc (GCC) 4.7.4 20130731 (prerelease)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


C:\var\building>gcc -O2 test.c

C:\var\building>a
small_text rc = 3
big_text rc = -1
Assertion failed!

Program: C:\var\building\a.exe
File: test.c, Line 24

Expression: rc > 0

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

C:\var\building>gcc -O2 -D __USE_MINGW_ANSI_STDIO test.c

C:\var\building>a
small_text rc = 3
big_text rc = 20

C:\var\building>gcc -O2 -D _POSIX test.c

C:\var\building>a
small_text rc = 3
big_text rc = 20

Or you can modify _mingw_mac.h, define __USE_MINGW_ANSI_STDIO or _POSIX .



Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to