[Piglit] [PATCH] cmake: Enable __USE_MINGW_ANSI_STDIO for MinGW builds.

Jose Fonseca jfonseca at vmware.com
Wed Aug 26 14:18:17 PDT 2015


On 18/08/15 05:11, Vinson Lee wrote:
> MSVC is currently already building getprogramresourceiv.c without any
> format-related warnings.

That's because MSVC will not warn about any format mismatches, no matter 
how bad they are.

(I think if one compiles with /analyze option, ie., static code 
analysis, it might warn, but I'm not entirely sure.)

> Also, this proposed patch would only apply to
> the MinGW build and have no effect the MSVC build.

Not directly, no.

But MinGW warnings (without __USE_MINGW_ANSI_STDIO) match bugs both on 
MinGW and MSVC.  So using __USE_MINGW_ANSI_STDIO will silence warnings 
with MinGW but will cause us to become blind to issues with MSVC -- 
we'll only notice when running on MSVC and test segfaults due to format 
mismatch.

I prefer MinGW build to be as close to MSVC as possible.  That is, I 
don't want MinGW to behave very differently from MSVC.  To avoid surprises.

Jose

> On Mon, Jul 20, 2015 at 11:51 PM, Jose Fonseca <jfonseca at vmware.com> wrote:
>> Interesting, I didn't know about __USE_MINGW_ANSI_STDIO.
>>
>> However, it solves the MinGW problem, but not MSVC --
>> https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx
>>
>> A more portable solution would be to use inttypes.h PRIdPTR or avoid size_t
>> arguments to printf.
>>
>> Jose
>>
>>
>> On 21/07/15 05:23, Vinson Lee wrote:
>>>
>>> Fix printf compiler warnings.
>>>
>>> getprogramresourceiv.c: In function 'check_prop':
>>> getprogramresourceiv.c:747:20: warning: unknown conversion type character
>>> 'z' in format [-Wformat=]
>>>       fprintf(stderr, "'%s' expected %zu entries but got %i"
>>
>>
>>
>>>                       ^
>>> getprogramresourceiv.c:747:20: warning: format '%i' expects argument of
>>> type 'int', but argument 4 has type 'size_t {aka long long unsigned int}'
>>> [-Wformat=]
>>> getprogramresourceiv.c:747:20: warning: too many arguments for format
>>> [-Wformat-extra-args]
>>> getprogramresourceiv.c:828:20: warning: unknown conversion type character
>>> 'z' in format [-Wformat=]
>>>       fprintf(stderr, "'%s' expected %zu entries but got %i"
>>>                       ^
>>> getprogramresourceiv.c:828:20: warning: format '%i' expects argument of
>>> type 'int', but argument 4 has type 'size_t {aka long long unsigned int}'
>>> [-Wformat=]
>>> getprogramresourceiv.c:828:20: warning: too many arguments for format
>>> [-Wformat-extra-args]
>>>
>>> Signed-off-by: Vinson Lee <vlee at freedesktop.org>
>>> ---
>>>    CMakeLists.txt | 2 ++
>>>    1 file changed, 2 insertions(+)
>>>
>>> diff --git a/CMakeLists.txt b/CMakeLists.txt
>>> index 99d9a8e..95a6b31 100644
>>> --- a/CMakeLists.txt
>>> +++ b/CMakeLists.txt
>>> @@ -280,6 +280,8 @@ if (MINGW)
>>>                  set (CMAKE_SHARED_LINKER_FLAGS
>>> "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
>>>                  set (CMAKE_MODULE_LINKER_FLAGS
>>> "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
>>>          endif ()
>>> +
>>> +       add_definitions(-D__USE_MINGW_ANSI_STDIO)
>>>    endif ()
>>>
>>>    if (${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
>>>
>>



More information about the Piglit mailing list