Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid warnings during build on several compilers #695

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

makise-homura
Copy link

Current Release build of jansson's master produces some warnings on several compilers, namely gcc 6.x, gcc 10.x, and lcc (eLbrus C/C++ compiler) 1.25 and 1.26. In addition, it uses incorrect format conversions on WIN32 in a couple places.

This PR fixes all this issues.

On each of my setups (different CPU arches, compilers, OS, etc.) both Release and Debug builds are now warningless, and all CTest tests pass successfully.

Igor Molchanov added 3 commits August 20, 2024 22:10
If jansson is built with -DCMAKE_BUILD_TYPE=Release, gcc 10.x (specifically,
gcc (Debian 10.2.1-6) 10.2.1 20210110) produces the following warning:

    jansson/src/error.c:25:9: warning: 'strncpy' specified bound depends
    on the length of the source argument [-Wstringop-overflow=]

This commit fixes this behavior.

Further info:
https://stackoverflow.com/questions/66930308/gcc-false-positive-warning-on-strncpy-usage
If jansson is built with -DCMAKE_BUILD_TYPE=Release, lcc 1.25 (specifically,
lcc:1.25.23:Apr--7-2022:e2k-v4-linux) and 1.26 (specifically,
lcc:1.26.20:Jun--6-2023:e2k-v4-linux) produce the following warnings:

    lcc: "/root/jansson/src/dtoa.c", line 3491: in function "strtod__unused":
    lcc: "/root/jansson/src/dtoa.c", line 4212: warning: variable "bb" may be
          used uninitialized [-Wmaybe-uninitialized]
    lcc: "/root/jansson/src/dtoa.c", line 4213: warning: variable "bd" may be
          used uninitialized [-Wmaybe-uninitialized]
    lcc: "/root/jansson/src/dtoa.c", line 4214: warning: variable "bs" may be
          used uninitialized [-Wmaybe-uninitialized]
    lcc: "/root/jansson/src/dtoa.c", line 4216: warning: variable "delta" may
          be used uninitialized [-Wmaybe-uninitialized]
    lcc: "/root/jansson/src/dtoa.c", line 5014: in function "dtoa_r":
    lcc: "/root/jansson/src/dtoa.c", line 5513: warning: variable "ulpmask" may
          be used uninitialized [-Wmaybe-uninitialized]

In addition, gcc 6.x (specifically, gcc (Debian 6.3.0-18+deb9u1) 6.3.0
20170516) produces only the last warning, probably because it may figure out
that strtod__unused() is actually unused, and skip this function.

This commit fixes this behavior.
If jansson is built on Windows (specifically, with MinGW 7.3.0), it produces
the following warnings:

    C:/Users/ci_user/jansson/examples/simple_parse.c:93:30: warning: unknown
        conversion type character 'l' in format [-Wformat=]

    C:/Users/ci_user/jansson/examples/simple_parse.c:106:29: warning: unknown
        conversion type character 'l' in format [-Wformat=]

Plus there are more additional warnings caused by code being treated
incorrectly because of these two.

It means it can't recognize "%lld" format specifier, which is, for Windows,
should be "%I64d". It has already been done for JSON_INTEGER_FORMAT, and I did
the same way for new macro, JSON_LONG_LONG_FORMAT.

So this commit fixes this behavior.

Further info:
https://sourceforge.net/p/mingw/bugs/2190/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant