strftime wrapper: "warning: format not a string literal, format string not checked"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all:

I have written the following strftime() wrapper:


__attribute__ ((format (strftime, 3, 0) ))
inline size_t strftime_e ( char * const s, const size_t max, const char * const format, const tm * const tm )
{
const size_t res = strftime( s, max, format, tm );

// This check is not watertight:
//  "Note that the return value 0 does not necessarily indicate an error.  For example, in many locales %p
//   yields an empty string.  An empty format string will likewise yield an empty string."
// But it should suffice for our purposes.
if ( 0 == res )
{
throw std::runtime_error( "Error calling strftime()." );
}

return res;
}



How can I prevent the following compilation warning on the strftime() call above?

warning: format not a string literal, format string not checked

Note that I am already trying with __attribute__ format to no avail. I am using GCC 7.3 for an embedded ARM Cortex-M4F target

Somebody else asked this same question in the past, but I saw no definitive answer:

https://gcc.gnu.org/ml/gcc-help/2009-02/msg00246.html

Please copy me on all the answers, for I am not subscribed to this list.


Thanks in advance,
  rdiez



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux