libcheck / check

A unit testing framework for C
GNU Lesser General Public License v2.1
1.08k stars 210 forks source link

windows with msys : warnings when printf functions #270

Open vtorri opened 4 years ago

vtorri commented 4 years ago

Here are the warnings :

check_error.c: In function 'emalloc':
check_error.c:64:29: warning: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'size_t' {aka 'long long unsigned int'} [-Wformat=]
   64 |         eprintf("malloc of %u bytes failed:", __FILE__, __LINE__ - 2, n);
      |                            ~^                                         ~
      |                             |                                         |
      |                             unsigned int                              size_t {aka long long unsigned int}
      |                            %llu
check_error.c: In function 'erealloc':
check_error.c:74:30: warning: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'size_t' {aka 'long long unsigned int'} [-Wformat=]
   74 |         eprintf("realloc of %u bytes failed:", __FILE__, __LINE__ - 2, n);
      |                             ~^                                         ~
      |                              |                                         |
      |                              unsigned int                              size_t {aka long long unsigned int}
      |                             %llu
check_pack.c: In function 'pack':
check_pack.c:139:33: warning: format '%d' expects argument of type 'int', but argument 4 has type 'size_t' {aka 'long long unsigned int'} [-Wformat=]
  139 |         eprintf("Value of len (%d) too big, max allowed %u\n",
      |                                ~^
      |                                 |
      |                                 int
      |                                %lld
  140 |                 __FILE__, __LINE__ - 3, len, INT_MAX);
      |                                         ~~~
      |                                         |
      |                                         size_t {aka long long unsigned int}
check_pack.c: In function 'upack':
check_pack.c:162:35: warning: unknown conversion type character ')' in format [-Wformat=]
  162 |         eprintf("Value of diff (%t) too big, max allowed %u\n",
      |                                   ^
check_pack.c:162:59: warning: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'ptrdiff_t' {aka 'long long int'} [-Wformat=]
  162 |         eprintf("Value of diff (%t) too big, max allowed %u\n",
      |                                                          ~^
      |                                                           |
      |                                                           unsigned int
      |                                                          %llu
  163 |                 __FILE__, __LINE__ - 3, diff, INT_MAX);
      |                                         ~~~~               
      |                                         |
      |                                         ptrdiff_t {aka long long int}
check_pack.c:162:17: warning: too many arguments for format [-Wformat-extra-args]
  162 |         eprintf("Value of diff (%t) too big, max allowed %u\n",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check_pack.c:165:35: warning: unknown conversion type character ')' in format [-Wformat=]
  165 |         eprintf("Value of diff (%t) too small, min allowed %u\n",
      |                                   ^
check_pack.c:165:61: warning: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'ptrdiff_t' {aka 'long long int'} [-Wformat=]
  165 |         eprintf("Value of diff (%t) too small, min allowed %u\n",
      |                                                            ~^
      |                                                             |
      |                                                             unsigned int
      |                                                            %llu
  166 |                 __FILE__, __LINE__ - 6, diff, INT_MIN);
      |                                         ~~~~                 
      |                                         |
      |                                         ptrdiff_t {aka long long int}
check_pack.c:165:17: warning: too many arguments for format [-Wformat-extra-args]
  165 |         eprintf("Value of diff (%t) too small, min allowed %u\n",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC       check_str.lo
vtorri commented 4 years ago

note that mingw-w64 uses msvcrt.dll, and %llu does not exist., use %Iu (uppercase i followed by u) for size_t types

brarcher commented 4 years ago

This should now be resolved from #271

brarcher commented 4 years ago

Per a comment from vtorri in #271,

Re-opening this bug.

brarcher commented 4 years ago

There is now a MSYS2 cross compile build as a part of pull request checks [example]. That should make it easier to confirm a fix.