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

build: enable -Wcast-qual, fix or silence compiler warnings #16142

Closed
wants to merge 141 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Jan 31, 2025

The issues found fell into these categories, with the applied fixes:

  • const was accidentally stripped.
    Adjust code to not cast or cast with const.

  • const/volatile missing from arguments, local variables.
    Constify arguments or variables, adjust/delete casts. Small code
    changes in a few places.

  • const must be stripped because an API dependency requires it.
    Strip const with CURL_UNCONST() macro to silence the warning out
    of our control. These happen at API boundaries. Sometimes they depend
    on dependency version, which this patch handles as necessary. Also
    enable const support for the zlib API, using ZLIB_CONST. Supported
    by zlib 1.2.5.2 and newer.

  • const must be stripped because a curl API requires it.
    Strip const with CURL_UNCONST() macro to silence the warning out
    of our immediate control. For example we promise to send a non-const
    argument to a callback, though the data is const internally.

  • other cases where we may avoid const stripping by code changes.
    Also silenced with CURL_UNCONST().

  • there are 3 places where CURL_UNCONST() is cast again to const.
    To silence this type of warning:

    lib/vquic/curl_osslq.c:1015:29: error: to be safe all intermediate pointers in cast from 'unsigned char **' to 'const unsigned char **' must be 'const' qualified [-Werror=cast-qual]
    lib/cf-socket.c:734:32: error: to be safe all intermediate pointers in cast from 'char **' to 'const char **' must be 'const' qualified [-Werror=cast-qual]
    

    There may be a better solution, but I couldn't find it.

These cases are handled in separate subcommits, but without further
markup. They seem fairly easily distinguishable (let me know if not!).

If you see a -Wcast-qual warning in curl, we appreciate your report
about it.


@vszakats vszakats added the build label Jan 31, 2025
@vszakats vszakats marked this pull request as draft January 31, 2025 22:21
@vszakats vszakats changed the title build: try -cast-qual [TEST] build: try -cast-qual Jan 31, 2025
@vszakats vszakats closed this Feb 1, 2025
@vszakats vszakats reopened this Feb 4, 2025
@vszakats vszakats changed the title [TEST] build: try -cast-qual [TEST] build: try -cast-qual, fix issues Feb 4, 2025
@vszakats vszakats changed the title [TEST] build: try -cast-qual, fix issues [WIP build: try -cast-qual, fix issues Feb 4, 2025
@vszakats vszakats changed the title [WIP build: try -cast-qual, fix issues [WIP] build: try -cast-qual, fix issues Feb 4, 2025
@vszakats vszakats marked this pull request as ready for review March 3, 2025 02:45
@vszakats vszakats changed the title [WIP] build: try -cast-qual, fix issues build: enable -Wcast-qual, fix or silence compiler warnings Mar 3, 2025
@vszakats vszakats force-pushed the cast-qual branch 13 times, most recently from bc699e6 to 227dae2 Compare March 4, 2025 02:57
vszakats added 24 commits March 10, 2025 14:08
…ace with CURL_UNCONST and undropping const fixup try 1

gcc-12, 13, 14 do not like this:
```
/Users/runner/work/curl/curl/lib/vtls/sectransp.c: In function 'CopyIdentityWithLabel':
/Users/runner/work/curl/curl/lib/curl_setup.h:984:34: error: cast from function call of type 'const void *' to non-matching type 'long unsigned int' [-Werror=bad-function-cast]
  984 | #define CURL_UNCONST(p) ((void *)(CURL_UNCONST_TYPE)(const void *)(p))
      |                                  ^
/Users/runner/work/curl/curl/lib/vtls/sectransp.c:540:27: note: in expansion of macro 'CURL_UNCONST'
  540 |           (SecIdentityRef)CURL_UNCONST(CFArrayGetValueAtIndex(keys_list, i));
      |                           ^~~~~~~~~~~~
```
https://github.com/curl/curl/actions/runs/13644166834/job/38139876978?pr=16142#step:9:20
@vszakats
Copy link
Member Author

Thank you all for the feedback and review! This is merged now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants