From 2b31129ef027b6d39e09b90d950ce0996eb8ef84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= <joakim.nohlgard@eistec.se>
Date: Thu, 14 Jun 2018 22:46:33 +0200
Subject: [PATCH] sys/cbor: Fix -Wformat=2 warnings

---
 sys/cbor/cbor.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sys/cbor/cbor.c b/sys/cbor/cbor.c
index b081368bf8..2376693bb3 100644
--- a/sys/cbor/cbor.c
+++ b/sys/cbor/cbor.c
@@ -87,6 +87,7 @@
 
 /* Array size */
 #define MAX_TIMESTRING_LENGTH   (21)
+#define TIMESTRING_FORMAT "%Y-%m-%dT%H:%M:%SZ"
 
 #ifndef INFINITY
 #define INFINITY (1.0/0.0)
@@ -767,9 +768,8 @@ size_t cbor_deserialize_date_time(const cbor_stream_t *stream, size_t offset, st
     char buffer[21];
     offset++;  /* skip tag byte to decode date_time */
     size_t read_bytes = cbor_deserialize_unicode_string(stream, offset, buffer, sizeof(buffer));
-    const char *format = "%Y-%m-%dT%H:%M:%SZ";
 
-    if (strptime(buffer, format, val) == 0) {
+    if (strptime(buffer, TIMESTRING_FORMAT, val) == 0) {
         return 0;
     }
 
@@ -787,9 +787,8 @@ size_t cbor_serialize_date_time(cbor_stream_t *stream, struct tm *val)
     CBOR_ENSURE_SIZE(stream, MAX_TIMESTRING_LENGTH + 1); /* + 1 tag byte */
 
     char time_str[MAX_TIMESTRING_LENGTH];
-    const char *format = "%Y-%m-%dT%H:%M:%SZ";
 
-    if (strftime(time_str, sizeof(time_str), format, val) == 0) { /* struct tm to string */
+    if (strftime(time_str, sizeof(time_str), TIMESTRING_FORMAT, val) == 0) { /* struct tm to string */
         return 0;
     }
 
@@ -1017,7 +1016,7 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
                     char buf[64];
                     struct tm timeinfo;
                     size_t read_bytes = cbor_deserialize_date_time(stream, offset, &timeinfo);
-                    strftime(buf, sizeof(buf), "%c", &timeinfo);
+                    strftime(buf, sizeof(buf), TIMESTRING_FORMAT, &timeinfo);
                     printf("(tag: %u, date/time string: \"%s\")\n", tag, buf);
                     return read_bytes;
                 }
-- 
GitLab