Skip to content

Add printf format attribute to OFFile printf wrappers - #151

Open
hjmjohnson wants to merge 1 commit into
DCMTK:masterfrom
hjmjohnson:offile-format-attribute
Open

Add printf format attribute to OFFile printf wrappers#151
hjmjohnson wants to merge 1 commit into
DCMTK:masterfrom
hjmjohnson:offile-format-attribute

Conversation

@hjmjohnson

Copy link
Copy Markdown

OFFile::fprintf and OFFile::vfprintf forward their format parameter to ::vfprintf, which triggers clang/gcc -Wformat-nonliteral in every translation unit that includes offile.h.

Annotating the two wrappers with __attribute__((format(printf, ...))) (guarded, empty on other compilers) marks the parameter as a valid forwarding target — silencing the wrapper-internal warning — and additionally gives all callers compile-time format/argument checking.

Found while building ITK, which vendors DCMTK and compiles with -Wformat-nonliteral enabled.

OFFile::fprintf and OFFile::vfprintf forward their format parameter to
::vfprintf, which triggers clang/gcc -Wformat-nonliteral in every
translation unit that includes offile.h. Annotating the wrappers with
__attribute__((format(printf, ...))) marks the parameter as a valid
forwarding target and gives callers full format/argument checking.
@hjmjohnson
hjmjohnson marked this pull request as ready for review July 12, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants