Skip to content

WIP: COMP: fixed some clang -Wformat-nonliteral warnings #5065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ namespace itk
#define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
#define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal

// For GCC/Clang, to decorate printf-like functions allowing for compiler checks of format strings.
#if defined(__GNUC__)
# define ITK_FORMAT_PRINTF(a, b) __attribute__((format(printf, a, b)))
#else
# define ITK_FORMAT_PRINTF(a, b)
#endif

#if !defined(ITK_LEGACY_REMOVE)
// Issue warning if deprecated preprocessor flag is used.
# define CLANG_SUPPRESS_Wcpp14_extensions \
Expand Down
18 changes: 10 additions & 8 deletions Modules/IO/TIFF/src/itkTIFFReaderInternal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class tiff_open_options_free
}
};

ITK_FORMAT_PRINTF(4, 0)
int
itkTIFFErrorHandlerExtR([[maybe_unused]] TIFF * tif,
[[maybe_unused]] void * user_data,
Expand All @@ -49,17 +50,18 @@ itkTIFFErrorHandlerExtR([[maybe_unused]] TIFF * tif,
if (::itk::Object::GetGlobalWarningDisplay() && !self->m_ErrorSilence)
{
char out[256];
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wformat_nonliteral;
vsnprintf(out, 256, fmt, ap);
ITK_GCC_PRAGMA_POP
// ITK_GCC_PRAGMA_PUSH
// ITK_GCC_SUPPRESS_Wformat_nonliteral;
vsnprintf(out, sizeof(out), fmt, ap);
// ITK_GCC_PRAGMA_POP
std::ostringstream itkmsg;
itkmsg << "ERROR: libtiff(" << (module ? module : "") << ") message: " << out << std::endl;
::itk::OutputWindowDisplayErrorText(itkmsg.str().c_str());
}
return 1;
}

ITK_FORMAT_PRINTF(4, 0)
int
itkTIFFWarningHandlerExtR([[maybe_unused]] TIFF * tif,
[[maybe_unused]] void * user_data,
Expand All @@ -72,10 +74,10 @@ itkTIFFWarningHandlerExtR([[maybe_unused]] TIFF * tif,
if (::itk::Object::GetGlobalWarningDisplay() && !self->m_WarningSilence)
{
char out[256];
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wformat_nonliteral;
vsnprintf(out, 256, fmt, ap);
ITK_GCC_PRAGMA_POP
// ITK_GCC_PRAGMA_PUSH
// ITK_GCC_SUPPRESS_Wformat_nonliteral;
vsnprintf(out, sizeof(out), fmt, ap);
// ITK_GCC_PRAGMA_POP
std::ostringstream itkmsg;
itkmsg << "WARNING: libtiff(" << (module ? module : "") << ") message: " << out << std::endl;
::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());
Expand Down
Loading