Skip to content

Commit acedf5a

Browse files
committed
sys/log: add format attribute to modlog_printf prototype
Add format(printf) attribute to modlog_printf to enable compile-time checking that format strings match arguments. Note that this will cause incorrect modlog_printf usage which previously compiled successfully, to no longer compile.
1 parent a52f357 commit acedf5a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

net/oic/src/port/mynewt/ip_adaptor.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <assert.h>
2121
#include <string.h>
2222
#include <stdint.h>
23+
#include <inttypes.h>
2324

2425
#include "os/mynewt.h"
2526

@@ -165,7 +166,7 @@ oc_send_buffer_ip6_int(struct os_mbuf *m, int is_mcast)
165166
to.msin6_scope_id = itf2.mif_idx;
166167
rc = mn_sendto(oc_ucast6, n, (struct mn_sockaddr *) &to);
167168
if (rc != 0) {
168-
OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
169+
OC_LOG_ERROR("Failed to send buffer %u on itf %" PRIu32 "\n",
169170
OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
170171
STATS_INC(oc_ip_stats, oerr);
171172
os_mbuf_free_chain(n);
@@ -176,7 +177,7 @@ oc_send_buffer_ip6_int(struct os_mbuf *m, int is_mcast)
176177
to.msin6_scope_id = itf2.mif_idx;
177178
rc = mn_sendto(oc_ucast6, m, (struct mn_sockaddr *) &to);
178179
if (rc != 0) {
179-
OC_LOG_ERROR("Failed sending buffer %u on itf %d\n",
180+
OC_LOG_ERROR("Failed sending buffer %u on itf %" PRIu32 "\n",
180181
OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
181182
STATS_INC(oc_ip_stats, oerr);
182183
os_mbuf_free_chain(m);
@@ -187,7 +188,7 @@ oc_send_buffer_ip6_int(struct os_mbuf *m, int is_mcast)
187188
} else {
188189
rc = mn_sendto(oc_ucast6, m, (struct mn_sockaddr *) &to);
189190
if (rc != 0) {
190-
OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
191+
OC_LOG_ERROR("Failed to send buffer %u on itf %" PRIu32 "\n",
191192
OS_MBUF_PKTHDR(m)->omp_len, to.msin6_scope_id);
192193
STATS_INC(oc_ip_stats, oerr);
193194
os_mbuf_free_chain(m);

net/osdp/src/osdp_phy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ osdp_phy_check_packet(struct osdp_pd *pd, uint8_t *buf, int len,
282282

283283
if (!ISSET_FLAG(pd, PD_FLAG_PD_MODE) &&
284284
!(pkt->pd_address & 0x80)) {
285-
OSDP_LOG_ERROR("Reply without address MSB set!\n", pkt->pd_address);
285+
OSDP_LOG_ERROR("Reply without address MSB set 0x%02x!\n", pkt->pd_address);
286286
return OSDP_ERR_PKT_FMT;
287287
}
288288

sys/log/modlog/include/modlog/modlog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ int modlog_foreach(modlog_foreach_fn *fn, void *arg);
190190
* @param level The severity of the log entry to write.
191191
* @param msg The "printf" formatted string to write.
192192
*/
193-
void modlog_printf(uint8_t module, uint8_t level, const char *msg, ...);
193+
void modlog_printf(uint8_t module, uint8_t level, const char *msg, ...)
194+
__attribute((format(printf, 3, 4)));
194195

195196
/**
196197
* @brief Writes a specified number of bytes as a text entry to the specified log module.

0 commit comments

Comments
 (0)