fix strftime() format string warning properly

the workaround for -Wformat triggered -Wformat-nonliteral in turn.
so instead go back to using pragmas and add a proper gcc version check.

this also works with clang - mostly for qt-creator's code model, which
is clang-based.

amends/reverts 55e65147.
This commit is contained in:
Oswald Buddenhagen 2019-07-28 20:42:04 +02:00
parent b885e0e03a
commit 27a1935361
2 changed files with 20 additions and 7 deletions

View File

@ -55,6 +55,22 @@ typedef unsigned long ulong;
# define ATTR_PACKED(ref)
#endif
#if defined(__clang__)
# define DO_PRAGMA__(text) _Pragma(#text)
# define DIAG_PUSH DO_PRAGMA__(clang diagnostic push)
# define DIAG_POP DO_PRAGMA__(clang diagnostic pop)
# define DIAG_DISABLE(text) DO_PRAGMA__(clang diagnostic ignored text)
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
# define DO_PRAGMA__(text) _Pragma(#text)
# define DIAG_PUSH DO_PRAGMA__(GCC diagnostic push)
# define DIAG_POP DO_PRAGMA__(GCC diagnostic pop)
# define DIAG_DISABLE(text) DO_PRAGMA__(GCC diagnostic ignored text)
#else
# define DIAG_PUSH
# define DIAG_POP
# define DIAG_DISABLE(text)
#endif
#if __GNUC__ >= 7
# define FALLTHROUGH __attribute__((fallthrough));
#else

View File

@ -2927,12 +2927,6 @@ imap_trash_msg( store_t *gctx, message_t *msg,
static void imap_store_msg_p2( imap_store_t *, imap_cmd_t *, int );
static size_t
my_strftime( char *s, size_t max, const char *fmt, const struct tm *tm )
{
return strftime( s, max, fmt, tm );
}
static void
imap_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
void (*cb)( int sts, uint uid, void *aux ), void *aux )
@ -2971,7 +2965,10 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
}
if (data->date) {
/* configure ensures that %z actually works. */
my_strftime( datestr, sizeof(datestr), "%d-%b-%Y %H:%M:%S %z", localtime( &data->date ) );
DIAG_PUSH
DIAG_DISABLE("-Wformat")
strftime( datestr, sizeof(datestr), "%d-%b-%Y %H:%M:%S %z", localtime( &data->date ) );
DIAG_POP
imap_exec( ctx, &cmd->gen, imap_store_msg_p2,
"APPEND \"%\\s\" %s\"%\\s\" ", buf, flagstr, datestr );
} else {