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

Enable and fix more GCC warnings #2747

Closed
wants to merge 5 commits into from

Conversation

MarcelRaad
Copy link
Member

This enables the following GCC flags:

When building with --enable-werror:

  • -pedantic-errors for GCC >= 5, which rejects some constructs which are no valid C and turns some undefined behavior into compile errors

When building with --enable-warnings:

  • -Wbad-function-cast, which was already enabled for clang, but not for GCC as it's a little stricter there - would have found telnet.c warning #2696 also with GCC
  • -Wimplicit-fallthrough=4 instead of the default 3, which makes the fallthrough comments more uniform
  • -Wold-style-definition
  • -ftree-vrp and -fdelete-null-pointer-checks, so that -Warray-bounds and -Wnull-dereference also work without --enable-optimize
  • level 2 instead of the default level 1 for -Wformat, -Warray-bounds, and -Wunused-const-variable

Also removes some unused definitions, but unfortunately the corresponding warning flag cannot be enabled as some occurrences are hard to fix.

Tested with

  • GCC 4.4 through 7 on Ubuntu 16.04 targeting Linux, Win64, Win32
  • GCC 4.8 on OpenSUSE Leap 42
  • GCC 4.8 on SLES 12
  • GCC 6 on MinGW/MSYS
  • GCC 7 on MinGW-w64/MSYS2 targeting Win64, Win32, MSYS
  • GCC 7 on Cygwin

@MarcelRaad MarcelRaad added build feature-window A merge of this requires an open feature window labels Jul 14, 2018
@@ -62,6 +62,7 @@ int test(char *URL)
struct curl_forms formarray[3];
size_t formlength = 0;
char flbuf[32];
long contentlength = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a curl_off_t ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecated CURLFORM_CONTENTSLENGTH used here uses long. I used the same cast sequence as in formdata.c. The newer CURLFORM_CONTENTLEN uses curl_off_t. If you want, I can switch to that in a separate commit before this one.

/* Use a form array for the non-copy test. */
formarray[0].option = CURLFORM_PTRCONTENTS;
formarray[0].value = data;
formarray[1].option = CURLFORM_CONTENTSLENGTH;
formarray[1].value = (char *) strlen(data) - 1;
formarray[1].value = (char *)(size_t)contentlength;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this too. Even if they're highly likely to use the same size...

@@ -94,11 +95,13 @@ int test(char *URL)
goto test_cleanup;
}

contentlength = (long)(strlen(data) - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and this

@bagder
Copy link
Member

bagder commented Aug 21, 2018

@MarcelRaad, what's the reason this is marked for next feature window and can't go in already now?

@MarcelRaad
Copy link
Member Author

@bagder The reason at that time was that I thought I wouldn't have enough time to see if all autobuilds pass without new warnings and fix them if not for 7.61.1. As the release date is now September 5, I'll merge right now and watch the autobuilds. Thanks!

@bagder
Copy link
Member

bagder commented Aug 21, 2018

Excellent! 👍

@MarcelRaad MarcelRaad removed the feature-window A merge of this requires an open feature window label Aug 21, 2018
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747
MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747
MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747
MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747
MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Aug 21, 2018
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747
@MarcelRaad MarcelRaad deleted the gcc-warnings branch August 21, 2018 16:57
xquery pushed a commit to xquery/curl that referenced this pull request Sep 3, 2018
xquery pushed a commit to xquery/curl that referenced this pull request Sep 3, 2018
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747
xquery pushed a commit to xquery/curl that referenced this pull request Sep 3, 2018
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747
xquery pushed a commit to xquery/curl that referenced this pull request Sep 3, 2018
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747
xquery pushed a commit to xquery/curl that referenced this pull request Sep 3, 2018
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
Enable pedantic-errors for GCC >= 5 with --enable-werror. Before GCC 5,
pedantic-errors was synonymous to -Werror=pedantic [0], which is still
the case for clang [1]. With GCC 5, it became complementary [2].

Also fix a resulting error in acinclude.m4 as main's return type was
missing, which is illegal in C99.

[0] https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Warning-Options.html
[1] https://clang.llvm.org/docs/UsersManual.html#options-to-control-error-and-warning-messages
[2] https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Warning-Options.html

Closes curl#2747
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
This warning used to be enabled only for clang as it's a bit stricter
on GCC. Silence the remaining occurrences and enable it on GCC too.

Closes curl#2747
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
This enables level 4 instead of the default level 3, which of the
currently used comments only allows /* FALLTHROUGH */ to silence the
warning.

Closes curl#2747
falconindy pushed a commit to falconindy/curl that referenced this pull request Sep 10, 2018
This enables the following additional warnings:
-Wold-style-definition
-Warray-bounds=2 instead of the default 1
-Wformat=2, but only for GCC 4.8+ as Wno-format-nonliteral is not
 respected for older versions
-Wunused-const-variable, which enables level 2 instead of the default 1
-Warray-bounds also in debug mode through -ftree-vrp
-Wnull-dereference also in debug mode through
 -fdelete-null-pointer-checks

Closes curl#2747
@lock lock bot locked as resolved and limited conversation to collaborators Nov 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants