Use PRI macros for safe printf and logs

This commit is contained in:
Simon Duquennoy 2018-02-23 04:47:18 -08:00
parent ef59ce132f
commit 9596a4285e
16 changed files with 48 additions and 50 deletions

View File

@ -314,7 +314,7 @@ add_req_handler(const linkaddr_t *peer_addr,
sizeof(sixp_pkt_cell_options_t) + sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) + sizeof(sixp_pkt_num_cells_t) +
sizeof(sf_plugtest_cell_t))) { sizeof(sf_plugtest_cell_t))) {
LOG_ERR("invalid Add Request length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Add Request length: %lu\n", (unsigned long)body_len);
} }
assert( assert(
sixp_pkt_get_cell_options(SIXP_PKT_TYPE_REQUEST, sixp_pkt_get_cell_options(SIXP_PKT_TYPE_REQUEST,
@ -359,7 +359,7 @@ add_res_handler(const linkaddr_t *peer_addr, sixp_pkt_rc_t rc,
struct tsch_slotframe *slotframe; struct tsch_slotframe *slotframe;
if(body_len != 4) { if(body_len != 4) {
LOG_ERR("invalid Add Response length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Add Response length: %lu\n", (unsigned long)body_len);
return; return;
} }
@ -399,7 +399,7 @@ delete_req_handler(const linkaddr_t *peer_addr,
sizeof(sixp_pkt_cell_options_t) + sizeof(sixp_pkt_cell_options_t) +
sizeof(sixp_pkt_num_cells_t) + sizeof(sixp_pkt_num_cells_t) +
sizeof(sf_plugtest_cell_t))) { sizeof(sf_plugtest_cell_t))) {
LOG_ERR("invalid Delete Request length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Delete Request length: %lu\n", (unsigned long)body_len);
} }
assert( assert(
sixp_pkt_get_cell_options(SIXP_PKT_TYPE_REQUEST, sixp_pkt_get_cell_options(SIXP_PKT_TYPE_REQUEST,
@ -446,7 +446,7 @@ delete_res_handler(const linkaddr_t *peer_addr, sixp_pkt_rc_t rc,
uint16_t timeslot; uint16_t timeslot;
if(body_len != 4) { if(body_len != 4) {
LOG_ERR("invalid Delete Response length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Delete Response length: %lu\n", (unsigned long)body_len);
return; return;
} }
@ -489,7 +489,7 @@ count_req_handler(const linkaddr_t *peer_addr,
assert(peer_addr != NULL && body != NULL); assert(peer_addr != NULL && body != NULL);
if(body_len != (sizeof(sixp_pkt_metadata_t) + if(body_len != (sizeof(sixp_pkt_metadata_t) +
sizeof(sixp_pkt_cell_options_t))) { sizeof(sixp_pkt_cell_options_t))) {
LOG_ERR("invalid Count Request length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Count Request length: %lu\n", (unsigned long)body_len);
} }
assert( assert(
sixp_pkt_get_cell_options(SIXP_PKT_TYPE_REQUEST, sixp_pkt_get_cell_options(SIXP_PKT_TYPE_REQUEST,
@ -534,7 +534,7 @@ count_res_handler(const linkaddr_t *peer_addr, sixp_pkt_rc_t rc,
sixp_pkt_total_num_cells_t total_num_cells; sixp_pkt_total_num_cells_t total_num_cells;
if(body_len != 2) { if(body_len != 2) {
LOG_ERR("invalid Count Response length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Count Response length: %lu\n", (unsigned long)body_len);
return; return;
} }
@ -570,7 +570,7 @@ list_req_handler(const linkaddr_t *peer_addr,
sizeof(sixp_pkt_reserved_t) + sizeof(sixp_pkt_reserved_t) +
sizeof(sixp_pkt_offset_t) + sizeof(sixp_pkt_offset_t) +
sizeof(sixp_pkt_max_num_cells_t))) { sizeof(sixp_pkt_max_num_cells_t))) {
LOG_ERR("invalid List Request length: %u\n", (unsigned int)body_len); LOG_ERR("invalid List Request length: %lu\n", (unsigned long)body_len);
} }
assert( assert(
@ -679,7 +679,7 @@ clear_req_handler(const linkaddr_t *peer_addr,
assert(peer_addr != NULL && body != NULL); assert(peer_addr != NULL && body != NULL);
if(body_len != sizeof(sixp_pkt_metadata_t)) { if(body_len != sizeof(sixp_pkt_metadata_t)) {
LOG_ERR("invalid Clear Request length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Clear Request length: %lu\n", (unsigned long)body_len);
} }
if((slotframe = tsch_schedule_get_slotframe_by_handle(0)) == NULL) { if((slotframe = tsch_schedule_get_slotframe_by_handle(0)) == NULL) {
@ -717,7 +717,7 @@ clear_res_handler(const linkaddr_t *peer_addr, sixp_pkt_rc_t rc,
} }
if(body_len != 0) { if(body_len != 0) {
LOG_ERR("invalid Clear Response length: %u\n", (unsigned int)body_len); LOG_ERR("invalid Clear Response length: %lu\n", (unsigned long)body_len);
return; return;
} }

View File

@ -83,7 +83,7 @@ multicast_send(void)
PRINTF("Send to: "); PRINTF("Send to: ");
PRINT6ADDR(&mcast_conn->ripaddr); PRINT6ADDR(&mcast_conn->ripaddr);
PRINTF(" Remote Port %u,", uip_ntohs(mcast_conn->rport)); PRINTF(" Remote Port %u,", uip_ntohs(mcast_conn->rport));
PRINTF(" (msg=0x%08lx)", (unsigned long)uip_ntohl(*((uint32_t *)buf))); PRINTF(" (msg=0x%08"PRIx32")", uip_ntohl(*((uint32_t *)buf)));
PRINTF(" %lu bytes\n", (unsigned long)sizeof(id)); PRINTF(" %lu bytes\n", (unsigned long)sizeof(id));
seq_id++; seq_id++;

View File

@ -347,7 +347,7 @@ heapmem_alloc(size_t size)
chunk->line = line; chunk->line = line;
#endif #endif
PRINTF("%s ptr %p size %u\n", __func__, GET_PTR(chunk), (unsigned)size); PRINTF("%s ptr %p size %lu\n", __func__, GET_PTR(chunk), (unsigned long)size);
return GET_PTR(chunk); return GET_PTR(chunk);
} }

View File

@ -82,8 +82,7 @@ progress_request(coap_request_state_t *state) {
coap_serialize_message(request, state->transaction->message); coap_serialize_message(request, state->transaction->message);
coap_send_transaction(state->transaction); coap_send_transaction(state->transaction);
LOG_DBG("Requested #%lu (MID %u)\n", (unsigned long)state->block_num, LOG_DBG("Requested #%"PRIu32" (MID %u)\n", state->block_num, request->mid);
request->mid);
} }
} }
@ -120,8 +119,7 @@ coap_request_callback(void *callback_data, coap_message_t *response)
/* this is only for counting BLOCK2 blocks.*/ /* this is only for counting BLOCK2 blocks.*/
++(state->block_num); ++(state->block_num);
} else { } else {
LOG_WARN("WRONG BLOCK %lu/%lu\n", (unsigned long)res_block, LOG_WARN("WRONG BLOCK %"PRIu32"/%"PRIu32"\n", res_block, state->block_num);
(unsigned long)state->block_num);
++block_error; ++block_error;
} }

View File

@ -507,7 +507,7 @@ output_to_peer(struct dtls_context_t *ctx,
struct uip_udp_conn *udp_connection = dtls_get_app_data(ctx); struct uip_udp_conn *udp_connection = dtls_get_app_data(ctx);
LOG_DBG("output_to DTLS peer ["); LOG_DBG("output_to DTLS peer [");
LOG_DBG_6ADDR(&session->ipaddr); LOG_DBG_6ADDR(&session->ipaddr);
LOG_DBG_("]:%u %d bytes\n", uip_ntohs(session->port), (int)len); LOG_DBG_("]:%u %ld bytes\n", uip_ntohs(session->port), (long)len);
uip_udp_packet_sendto(udp_connection, data, len, uip_udp_packet_sendto(udp_connection, data, len,
&session->ipaddr, session->port); &session->ipaddr, session->port);
return len; return len;

View File

@ -528,7 +528,7 @@ coap_parse_message(coap_message_t *coap_pkt, uint8_t *data, uint16_t data_len)
case COAP_OPTION_MAX_AGE: case COAP_OPTION_MAX_AGE:
coap_pkt->max_age = coap_parse_int_option(current_option, coap_pkt->max_age = coap_parse_int_option(current_option,
option_length); option_length);
LOG_DBG_("Max-Age [%lu]\n", (unsigned long)coap_pkt->max_age); LOG_DBG_("Max-Age [%"PRIu32"]\n", coap_pkt->max_age);
break; break;
case COAP_OPTION_ETAG: case COAP_OPTION_ETAG:
coap_pkt->etag_len = MIN(COAP_ETAG_LEN, option_length); coap_pkt->etag_len = MIN(COAP_ETAG_LEN, option_length);
@ -638,7 +638,7 @@ coap_parse_message(coap_message_t *coap_pkt, uint8_t *data, uint16_t data_len)
case COAP_OPTION_OBSERVE: case COAP_OPTION_OBSERVE:
coap_pkt->observe = coap_parse_int_option(current_option, coap_pkt->observe = coap_parse_int_option(current_option,
option_length); option_length);
LOG_DBG_("Observe [%lu]\n", (unsigned long)coap_pkt->observe); LOG_DBG_("Observe [%"PRId32"]\n", coap_pkt->observe);
break; break;
case COAP_OPTION_BLOCK2: case COAP_OPTION_BLOCK2:
coap_pkt->block2_num = coap_parse_int_option(current_option, coap_pkt->block2_num = coap_parse_int_option(current_option,
@ -666,11 +666,11 @@ coap_parse_message(coap_message_t *coap_pkt, uint8_t *data, uint16_t data_len)
break; break;
case COAP_OPTION_SIZE2: case COAP_OPTION_SIZE2:
coap_pkt->size2 = coap_parse_int_option(current_option, option_length); coap_pkt->size2 = coap_parse_int_option(current_option, option_length);
LOG_DBG_("Size2 [%lu]\n", (unsigned long)coap_pkt->size2); LOG_DBG_("Size2 [%"PRIu32"]\n", coap_pkt->size2);
break; break;
case COAP_OPTION_SIZE1: case COAP_OPTION_SIZE1:
coap_pkt->size1 = coap_parse_int_option(current_option, option_length); coap_pkt->size1 = coap_parse_int_option(current_option, option_length);
LOG_DBG_("Size1 [%lu]\n", (unsigned long)coap_pkt->size1); LOG_DBG_("Size1 [%"PRIu32"]\n", coap_pkt->size1);
break; break;
default: default:
LOG_DBG_("unknown (%u)\n", option_number); LOG_DBG_("unknown (%u)\n", option_number);

View File

@ -973,7 +973,7 @@ ra_input(void)
default: default:
LOG_DBG("Updating timer of prefix "); LOG_DBG("Updating timer of prefix ");
LOG_DBG_6ADDR(&prefix->ipaddr); LOG_DBG_6ADDR(&prefix->ipaddr);
LOG_DBG_(" new value %lu\n", (unsigned long)uip_ntohl(nd6_opt_prefix_info->validlt)); LOG_DBG_(" new value %"PRIu32"\n", uip_ntohl(nd6_opt_prefix_info->validlt));
stimer_set(&prefix->vlifetime, stimer_set(&prefix->vlifetime,
uip_ntohl(nd6_opt_prefix_info->validlt)); uip_ntohl(nd6_opt_prefix_info->validlt));
prefix->isinfinite = 0; prefix->isinfinite = 0;
@ -1034,7 +1034,7 @@ ra_input(void)
while(naddr-- > 0) { while(naddr-- > 0) {
LOG_DBG("nameserver: "); LOG_DBG("nameserver: ");
LOG_DBG_6ADDR(ip); LOG_DBG_6ADDR(ip);
LOG_DBG_(" lifetime: %lx\n", (unsigned long)uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime)); LOG_DBG_(" lifetime: %"PRIx32"\n", uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime));
uip_nameserver_update(ip, uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime)); uip_nameserver_update(ip, uip_ntohl(UIP_ND6_OPT_RDNSS_BUF->lifetime));
ip++; ip++;
} }

View File

@ -118,7 +118,7 @@ tsch_log_process_pending(void)
if(log->rx.drift_used) { if(log->rx.drift_used) {
printf(", dr %d", log->rx.drift); printf(", dr %d", log->rx.drift);
} }
printf(", edr %d\n", (int)log->rx.estimated_drift); printf(", edr %d\n", log->rx.estimated_drift);
break; break;
case tsch_log_message: case tsch_log_message:
printf("%s\n", log->message); printf("%s\n", log->message);

View File

@ -767,7 +767,7 @@ perform_multi_resource_read_op(lwm2m_object_t *object,
/* Now we need to initialize the object writing for this new object */ /* Now we need to initialize the object writing for this new object */
len = ctx->writer->init_write(ctx); len = ctx->writer->init_write(ctx);
ctx->outbuf->len += len; ctx->outbuf->len += len;
LOG_DBG("INIT WRITE len:%d size:%d\n", len, (int) ctx->outbuf->size); LOG_DBG("INIT WRITE len:%d size:%"PRIu16"\n", len, ctx->outbuf->size);
initialized = 1; initialized = 1;
} }
@ -1516,10 +1516,10 @@ lwm2m_handler_callback(coap_message_t *request, coap_message_t *response,
/* for debugging */ /* for debugging */
LOG_DBG("["); LOG_DBG("[");
LOG_DBG_COAP_STRING(url, url_len); LOG_DBG_COAP_STRING(url, url_len);
LOG_DBG_("] %s Format:%d ID:%d bsize:%u offset:%d\n", LOG_DBG_("] %s Format:%d ID:%d bsize:%u offset:%"PRId32"\n",
get_method_as_string(coap_get_method_type(request)), get_method_as_string(coap_get_method_type(request)),
format, context.object_id, buffer_size, format, context.object_id, buffer_size,
offset != NULL ? ((int)*offset) : 0); offset != NULL ? *offset : 0);
if(format == TEXT_PLAIN) { if(format == TEXT_PLAIN) {
/* a string */ /* a string */
const uint8_t *data; const uint8_t *data;
@ -1573,8 +1573,8 @@ lwm2m_handler_callback(coap_message_t *request, coap_message_t *response,
if(success == LWM2M_STATUS_OK) { if(success == LWM2M_STATUS_OK) {
/* Handle blockwise 1 */ /* Handle blockwise 1 */
if(coap_is_option(request, COAP_OPTION_BLOCK1)) { if(coap_is_option(request, COAP_OPTION_BLOCK1)) {
LOG_DBG("Setting BLOCK 1 num:%d o2:%d o:%d\n", (int) bnum, (int) boffset, LOG_DBG("Setting BLOCK 1 num:%"PRIu32" o2:%"PRIu32" o:%"PRId32"\n", bnum, boffset,
(int) (offset != NULL ? *offset : 0)); (offset != NULL ? *offset : 0));
coap_set_header_block1(response, bnum, 0, bsize); coap_set_header_block1(response, bnum, 0, bsize);
} }

View File

@ -177,7 +177,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
/* Handle the writes */ /* Handle the writes */
switch(ctx->resource_id) { switch(ctx->resource_id) {
case LWM2M_SECURITY_SERVER_URI_ID: case LWM2M_SECURITY_SERVER_URI_ID:
LOG_DBG("Writing security URI value: len: %d\n", (int)ctx->inbuf->size); LOG_DBG("Writing security URI value: len: %"PRId16"\n", ctx->inbuf->size);
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->server_uri, LWM2M_SECURITY_URI_SIZE); value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->server_uri, LWM2M_SECURITY_URI_SIZE);
/* This is string... */ /* This is string... */
security->server_uri_len = ctx->last_value_len; security->server_uri_len = ctx->last_value_len;
@ -204,7 +204,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->public_key, LWM2M_SECURITY_KEY_SIZE); value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->public_key, LWM2M_SECURITY_KEY_SIZE);
security->public_key_len = ctx->last_value_len; security->public_key_len = ctx->last_value_len;
LOG_DBG("Writing client PKI: len: %d '", (int)ctx->last_value_len); LOG_DBG("Writing client PKI: len: %"PRIu16" '", ctx->last_value_len);
LOG_DBG_COAP_STRING((const char *)security->public_key, LOG_DBG_COAP_STRING((const char *)security->public_key,
ctx->last_value_len); ctx->last_value_len);
LOG_DBG_("'\n"); LOG_DBG_("'\n");
@ -213,7 +213,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->secret_key, LWM2M_SECURITY_KEY_SIZE); value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->secret_key, LWM2M_SECURITY_KEY_SIZE);
security->secret_key_len = ctx->last_value_len; security->secret_key_len = ctx->last_value_len;
LOG_DBG("Writing secret key: len: %d '", (int)ctx->last_value_len); LOG_DBG("Writing secret key: len: %"PRIu16" '", ctx->last_value_len);
LOG_DBG_COAP_STRING((const char *)security->secret_key, LOG_DBG_COAP_STRING((const char *)security->secret_key,
ctx->last_value_len); ctx->last_value_len);
LOG_DBG_("'\n"); LOG_DBG_("'\n");

View File

@ -205,7 +205,7 @@ lwm2m_tlv_write_int32(uint8_t type, int16_t id, int32_t value, uint8_t *buffer,
int i; int i;
int v; int v;
int last_bit; int last_bit;
LOG_DBG("Exporting int32 %d %ld ", id, (long)value); LOG_DBG("Exporting int32 %d %"PRId32" ", id, value);
v = value < 0 ? -1 : 0; v = value < 0 ? -1 : 0;
i = 0; i = 0;
@ -252,9 +252,9 @@ lwm2m_tlv_write_float32(uint8_t type, int16_t id, int32_t value, int bits,
e++; e++;
} }
LOG_DBG("Sign: %d, Fraction: %06lx 0b", value < 0, (long)val); LOG_DBG("Sign: %d, Fraction: %06"PRIx32" 0b", value < 0, val);
for(i = 0; i < 23; i++) { for(i = 0; i < 23; i++) {
LOG_DBG_("%d", (int)((val >> (22 - i)) & 1)); LOG_DBG_("%"PRId32"", ((val >> (22 - i)) & 1));
} }
LOG_DBG_("\nExp:%d\n", e); LOG_DBG_("\nExp:%d\n", e);
@ -292,9 +292,9 @@ lwm2m_tlv_float32_to_fix(const lwm2m_tlv_t *tlv, int32_t *value, int bits)
e = ((tlv->value[0] << 1) & 0xff) | (tlv->value[1] >> 7); e = ((tlv->value[0] << 1) & 0xff) | (tlv->value[1] >> 7);
val = (((long)tlv->value[1] & 0x7f) << 16) | (tlv->value[2] << 8) | tlv->value[3]; val = (((long)tlv->value[1] & 0x7f) << 16) | (tlv->value[2] << 8) | tlv->value[3];
LOG_DBG("Sign: %d, Fraction: %06lx 0b", val < 0, (long)val); LOG_DBG("Sign: %d, Fraction: %06"PRIx32" 0b", val < 0, val);
for(i = 0; i < 23; i++) { for(i = 0; i < 23; i++) {
LOG_DBG_("%d", (int)((val >> (22 - i)) & 1)); LOG_DBG_("%"PRId32"", ((val >> (22 - i)) & 1));
} }
LOG_DBG("\nExp:%d => %d\n", e, e - 127); LOG_DBG("\nExp:%d => %d\n", e, e - 127);

View File

@ -106,7 +106,7 @@ void
ctimer_set_with_process(struct ctimer *c, clock_time_t t, ctimer_set_with_process(struct ctimer *c, clock_time_t t,
void (*f)(void *), void *ptr, struct process *p) void (*f)(void *), void *ptr, struct process *p)
{ {
PRINTF("ctimer_set %p %u\n", c, (unsigned)t); PRINTF("ctimer_set %p %lu\n", c, (unsigned long)t);
c->p = p; c->p = p;
c->f = f; c->f = f;
c->ptr = ptr; c->ptr = ptr;