Skip to content

build: use -Wno-format-overflow - #14598

Closed
bagder wants to merge 1 commit into
masterfrom
bagder/format-overflow
Closed

bagder wants to merge 1 commit into
masterfrom
bagder/format-overflow

Conversation

@bagder

@bagder bagder commented Aug 19, 2024 •

Copy link
Copy Markdown
Member

-Wformat-overflow is not a warning that we want enabled as it does not help us. It can only bring us false positives since it warns on bad uses of sprintf and vsprintf ("that might overflow the destination buffer"). Two functions we explicitly ban in curl code.

The only way this flag triggers warnings in curl code is false positives for functions we have marked with the CURL_PRINTF() macro.

Further: it seems -Wformat-trunaction option might in turn also enable -Wformat-overflow, so if this second option is used, we need to explicitly set -Wno-format-overflow - not just skip setting -Wformat-overflow.

Reported-by: Viktor Szakats
Fixes #14168

-Wformat-overflow is not a warning that we want enabled as it does not
help us. It can only bring us false positives since it warng on bad uses
of sprintf and vsprintf ("that might overflow the destination buffer").
Two functions we explictly ban in curlcode.

The only way this flag triggers warnings in curl code is false positives
for functions we have marked with the CURL_PRINTF() macro.

Further: it seems -Wformat-trunaction option might in turn also enable
-Wformat-overflow, so if this second option is used, we need to
explcitly set -Wno-format-overflow - not just skip setting
-Wformat-overflow.

Reported-by: Viktor Szakats
Fixes #14168
@bagder bagder added the build label Aug 19, 2024
@vszakats

vszakats commented Aug 19, 2024 •

Copy link
Copy Markdown
Member

Further: it seems -Wformat-trunaction option might in turn also enable -Wformat-overflow, so if this second option is used, we need to explicitly set -Wno-format-overflow - not just skip setting -Wformat-overflow.

Which gcc version have you seen doing this?

Tried to reproduce with godbolt.org with -Wformat-truncation=2, but couldn't get the warning (without also explicitly adding -Wformat-overflow):
https://godbolt.org/z/EjEsn36dY

@bagder

bagder commented Aug 19, 2024

Copy link
Copy Markdown
Member Author

This was on my local machine using: gcc (Debian 14.2.0-2) 14.2.0

@bagder bagder closed this in 145f87b Aug 19, 2024
@bagder
bagder deleted the bagder/format-overflow branch August 19, 2024 21:21
vszakats added a commit that referenced this pull request Sep 23, 2024
…ilds

- lib557: suppress `-Wformat-overflow` warning in source.
  Fixes:
  ```
  lib557.c: In function ‘test_float_formatting’:
  lib557.c:1408:37: error: ‘%*f’ directive output of 2147483648 bytes exceeds ‘INT_MAX’ [-Werror=format-overflow=]
   1408 |   curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
        |                                     ^~~
  lib557.c:1408:3: note: ‘curl_msnprintf’ output 2147483649 bytes
   1408 |   curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
        |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ```
  Ref: https://app.circleci.com/pipelines/github/curl/curl/10226/workflows/87642ee9-cda6-4916-8206-c82aac5f595e/jobs/107669?invite=true#step-106-40996_46

  The root cause of why this option gets enabled remains undiscovered.

  Reported-by: Daniel Stenberg
  Fixes #15008
  Follow-up to 71cf0d1 #14772

- build: drop `-Wno-format-overflow` from picky warning list.
  These options only get used with picky warnings enabled.
  Follow-up to 145f87b #14598

- unit1652: suppress in source (and not rely on picky warnings anymore.)

Closes #15012
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
…ilds

- lib557: suppress `-Wformat-overflow` warning in source.
  Fixes:
  ```
  lib557.c: In function ‘test_float_formatting’:
  lib557.c:1408:37: error: ‘%*f’ directive output of 2147483648 bytes exceeds ‘INT_MAX’ [-Werror=format-overflow=]
   1408 |   curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
        |                                     ^~~
  lib557.c:1408:3: note: ‘curl_msnprintf’ output 2147483649 bytes
   1408 |   curl_msnprintf(buf, sizeof(buf), "%*f", INT_MIN, 9.1);
        |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ```
  Ref: https://app.circleci.com/pipelines/github/curl/curl/10226/workflows/87642ee9-cda6-4916-8206-c82aac5f595e/jobs/107669?invite=true#step-106-40996_46

  The root cause of why this option gets enabled remains undiscovered.

  Reported-by: Daniel Stenberg
  Fixes curl#15008
  Follow-up to 71cf0d1 curl#14772

- build: drop `-Wno-format-overflow` from picky warning list.
  These options only get used with picky warnings enabled.
  Follow-up to 145f87b curl#14598

- unit1652: suppress in source (and not rely on picky warnings anymore.)

Closes curl#15012
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.

http: gcc 14 compiler warning on mac arm64 (cmake, unity)

2 participants