Pārlūkot izejas kodu

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.
Oswald Buddenhagen 6 gadi atpakaļ
vecāks
revīzija
27a1935361
2 mainītis faili ar 20 papildinājumiem un 7 dzēšanām
  1. 16 0
      src/common.h
  2. 4 7
      src/drv_imap.c

+ 16 - 0
src/common.h

@@ -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

+ 4 - 7
src/drv_imap.c

@@ -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 {