Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ofstd/include/dcmtk/ofstd/offile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ END_EXTERN_C
#undef clearerr
#endif

/* Enable compile-time checking of arguments passed to the printf-style
* member functions of OFFile, and mark their format parameter as a valid
* forwarding target so -Wformat-nonliteral does not warn inside them.
* FMT is the 1-based position of the format string parameter and ARGS the
* position of the first variadic argument (0 for va_list functions); the
* implicit 'this' parameter of non-static member functions counts as
* parameter 1.
*/
#if defined(__GNUC__) || defined(__clang__)
#define OFFILE_FORMAT_PRINTF(FMT, ARGS) __attribute__((format(printf, FMT, ARGS)))
#else
#define OFFILE_FORMAT_PRINTF(FMT, ARGS)
#endif

/* When using the ISO C++ include files such as <cstdio>, <cstdarg> etc.,
* all ANSI C functions like fopen() are declared in namespace std,
* (e.g. we have to use std::fopen()), but non-ANSI Posix functions remain
Expand Down Expand Up @@ -884,6 +898,7 @@ class DCMTK_OFSTD_EXPORT OFFile
* @param ... further parameters according to format string
* @return number of characters printed
*/
OFFILE_FORMAT_PRINTF(2, 3)
int fprintf(const char *format, ...)
{
int result = 0;
Expand All @@ -899,6 +914,7 @@ class DCMTK_OFSTD_EXPORT OFFile
* @param arg list of further parameters according to format string
* @return number of characters printed
*/
OFFILE_FORMAT_PRINTF(2, 0)
int vfprintf(const char *format, va_list arg)
{
return :: vfprintf(file_, format, arg);
Expand Down
Loading