Skip to content

checksrc: add off-by-default PRINTFZ rule, enable for examples - #23383

Closed
vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:checksrc-printfz
Closed

vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:checksrc-printfz

Conversation

@vszakats

@vszakats vszakats commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

To catch the use of %zd/%zu masks in code that uses the CRT printfs.
This is currently in docs/example, and upcoming in tests/server in a
separate patch. These masks pass compilation in all supported compiler,
but, with the CRT of VS2013 and earlier, they result in a runtime crash.

There was existing use of these masks in examples.

Also:

Cherry-picked from #23378


  • add test.

@vszakats vszakats changed the title checksrc: add off-by-default PRINTFZ rule checksrc: add off-by-default PRINTFZ rule, enable for examples Oct 13, 2026
@vszakats
vszakats requested a lite review from Copilot October 13, 2026 09:05

This comment was marked as low quality.

This comment was marked as low quality.

@jay jay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest a comment in checksrc to explain what PRINTFZ is for. This could also be expanded on in the docs to explain the reason %z is banned from certain directories, because I don't think it's going to be immediately obvious to anyone except us.

Comment thread scripts/checksrc.pl Resolved
@vszakats vszakats closed this in 7f47b6e Oct 14, 2026
@vszakats
vszakats deleted the checksrc-printfz branch October 14, 2026 10:45
vszakats added a commit that referenced this pull request Oct 14, 2026
The test server code uses plain CRT printf functions, and uses the.
`%zd`, `%zu` masks in `logmsg()` calls. It compiles cleanly with all
supported compilers. But, the CRT of VS2013 (and earlier) do not
actually support these masks, and print `zd`/`zu` as-is instead. This by
itself would likely not break tests, but it also leaves the `[s]size_t`
varargs unconsumed, which crashes the server on the first client
request.

In practice this means that most tests relying on the test server,
failed. With `sws`, the symptom was a `Read zd bytes` message in the
log. E.g.: https://ci.appveyor.com/project/curlorg/curl/builds/54869181

Fix by using `%ld`/`%lu`, with matching casts.

Test run: https://ci.appveyor.com/project/curlorg/curl/builds/54882859
(remaining failures are unrelated.)

This has been a potential issue since 2008.

Also:
- dnsd: keep `n` as signed when printing it in `doh_conn_recv()`.
- tests/server: enable `PRINTFZ` checksrc rule for this directory, to
  avoid reintroducing a silent breakage by using these masks.

Bug: #23306 (comment)
Bug: #23306 (comment)
Ref: 7f47b6e #23383
Cherry-picked from #23306

Closes #23378
vszakats added a commit that referenced this pull request Oct 15, 2026
It's used in the codebase, but not in CRT printf calls. Make sure to not
introduce it there and break <VS2013.

Follow-up to 7f47b6e #23383

Closes #23414
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.

3 participants