Skip to content

websocket example: cast print values to unsigned int#18326

Closed
icing wants to merge 1 commit intocurl:masterfrom
icing:fix-ws-example
Closed

websocket example: cast print values to unsigned int#18326
icing wants to merge 1 commit intocurl:masterfrom
icing:fix-ws-example

Conversation

@icing
Copy link
Copy Markdown
Contributor

@icing icing commented Aug 20, 2025

To have not compiler warnings on format checks.

Reported By: Gisle Vanem

To have not compiler warnings on format checks.

Reported By: Gisle Vanem
icing referenced this pull request Aug 20, 2025
Make `docs/examples/websocket.c more complete by showing how to handle
CURLE_AGAIN return codes and incomplete sends.

Reported-by: Markus Unterwaditzer
Fixes #13288
Closes #17860
@icing icing requested a review from bagder August 20, 2025 14:48
@vszakats
Copy link
Copy Markdown
Member

Hm, wondering why CI did not catch this?

@bagder bagder closed this in 8515424 Aug 21, 2025
@vszakats
Copy link
Copy Markdown
Member

Do we know which compiler/version/option can trigger this?

/cc @gvanem

@gvanem
Copy link
Copy Markdown
Contributor

gvanem commented Aug 21, 2025

Do we know which compiler/version/option can trigger this?

With clang-cl -Wall at least. I do not know what warning level there is in CI.

@vszakats
Copy link
Copy Markdown
Member

@gvanem Thanks! I could reproduce. clang-cl translates a bare -Wall to -Weverything, which triggers a whole lot of warnings (and also anything new for new versions, so it isn't practical for CI). -clang:-Wall makes it behave like native clang -Wall, and this is the one tested in CI.

For CI it'd be nice to figure out how to enable this specific warning only. -Wformat doesn't do it.

"$(brew --prefix llvm)/bin/clang-cl" -v -target x86_64-windows-msvc -c -Wall -Wno-used-but-marked-unused -Wno-reserved-identifier websocket.c $inc -I../../include

websocket.c(92,66): warning: format specifies type 'unsigned int' but the argument has type 'int' [-Wformat]
   92 |       fprintf(stderr, "ws: received BINARY frame of %u bytes\n", (int)rlen);
      |                                                     ~~           ^~~~~~~~~
      |                                                     %d
websocket.c(96,69): warning: format specifies type 'unsigned int' but the argument has type 'int' [-Wformat]
   96 |       fprintf(stderr, "ws: received frame of %u bytes rflags %x\n", (int)rlen,
      |                                              ~~                     ^~~~~~~~~
      |                                              %d
websocket.c(97,15): warning: format specifies type 'unsigned int' but the argument has type 'int' [-Wformat]
   96 |       fprintf(stderr, "ws: received frame of %u bytes rflags %x\n", (int)rlen,
      |                                                              ~~
      |                                                              %x
   97 |               meta->flags);
      |               ^~~~~~~~~~~
websocket.c(49,7): warning: unsafe pointer arithmetic [-Wunsafe-buffer-usage]
   49 |       buf += sent; /* deduct what was sent */
      |       ^~~
websocket.c(147,41): warning: unsafe buffer access [-Wunsafe-buffer-usage]
  147 |     curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
      |                                         ^~~~

@vszakats
Copy link
Copy Markdown
Member

It's -Wformat-signedness I think:
https://clang.llvm.org/docs/DiagnosticsReference.html#wformat-signedness

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

Development

Successfully merging this pull request may close these issues.

4 participants