christophercrouzet / rexo

Neat single-file cross-platform unit testing framework for C/C++.
The Unlicense
27 stars 6 forks source link

warning: format string is not a string literal #8

Closed SamuelMarks closed 3 years ago

SamuelMarks commented 3 years ago
versions/downloaded_headers/rexo.h:5092:35: warning: format string is not a string literal [-Wformat-nonliteral]
              size = vfprintf(file, fmt, args);
                                    ^~~

91bd377/include/rexo.h#L4374

(Strangely, only happens on AppleClang)

christophercrouzet commented 3 years ago

Good morning @SamuelMarks!

Thank you for reporting this issue!

After some Googling, I believe having found how to address this warning, however I am not sure if this works as expected since I am unable to repro this issue (I have no macOS system, and GitHub's macOS workflow doesn't seem to report any warning).

I pushed the changes onto the branch main, so feel free to give it a go and to let me know if this works! :smile:

SamuelMarks commented 3 years ago

Maybe it's an extra -W, see https://github.com/SamuelMarks/cmake-example-with-vcpkg/actions/runs/1029597485

Okay cool will give your solution a shot

SamuelMarks commented 3 years ago
  In file included from /Users/runner/work/cmake-example-with-vcpkg/cmake-example-with-vcpkg/versions/versions_test.c:1:
  Warning: versions/downloaded_headers/rexo.h:5106:35: warning: format string is not a string literal [-Wformat-nonliteral]
              size = vfprintf(file, fmt, args);
                                    ^~~
  Warning: versions/downloaded_headers/rexo.h:5124:24: warning: format string is not a string literal [-Wformat-nonliteral]
      size = vsprintf(s, fmt, args);
                         ^~~
  /Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/include/secure/_stdio.h:66:57: note: expanded from macro 'vsprintf'
    __builtin___vsprintf_chk (str, 0, __darwin_obsz(str), format, ap)
                                                          ^~~~~~
  2 warnings generated.

I.e., https://github.com/christophercrouzet/rexo/blob/6164b40/include/rexo.h#L5106 https://github.com/christophercrouzet/rexo/blob/6164b40/include/rexo.h#L5124

So your solution solved 1 of the warnings

christophercrouzet commented 3 years ago

Maybe it's an extra -W

Spot on! I thought that the list of compiler warnings was already comprehensive enough but it looks like there are always more flags to uncover! :smile:

With this new flag, I could repro the warnings that you observed and I committed new changes that should address them. I didn't know that functions with va_args needed to be decorated as well!

Thanks for your help!

christophercrouzet commented 3 years ago

Hey @SamuelMarks, apologies, I just realized that I didn't even ask you if this was working for you, but seeing your thumbs up emoji, I'll assume that it's the case and will close this issue. But please feel free to reopen it otherwise!

I've released v0.2.1 with these changes: https://github.com/christophercrouzet/rexo/releases/tag/v0.2.1