|
21 | 21 | #include "sl_log.h"
|
22 | 22 |
|
23 | 23 | // Generic includes
|
| 24 | +#include <assert.h> |
24 | 25 | #include <string.h> // Using memcpy
|
25 | 26 | #include <cstdio> // snprintf
|
26 | 27 |
|
@@ -403,52 +404,93 @@ void zwave_tx_queue::log_element(const zwave_tx_session_id_t session_id,
|
403 | 404 | void zwave_tx_queue::simple_log(zwave_tx_queue_element_t *e) const
|
404 | 405 | {
|
405 | 406 | uint16_t index = 0;
|
406 |
| - index += snprintf(message + index, |
407 |
| - sizeof(message) - index, |
408 |
| - "Enqueuing new frame (id=%p)", |
409 |
| - e->zwave_tx_session_id); |
| 407 | + int written = snprintf(message + index, |
| 408 | + sizeof(message) - index, |
| 409 | + "Enqueuing new frame (id=%p)", |
| 410 | + e->zwave_tx_session_id); |
| 411 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 412 | + assert(false); |
| 413 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 414 | + return; |
| 415 | + } |
| 416 | + index += written; |
410 | 417 |
|
411 | 418 | if (e->options.transport.valid_parent_session_id == true) {
|
412 |
| - index += snprintf(message + index, |
413 |
| - sizeof(message) - index, |
414 |
| - " (parent id=%p)", |
415 |
| - e->options.transport.parent_session_id); |
| 419 | + written = snprintf(message + index, |
| 420 | + sizeof(message) - index, |
| 421 | + " (parent id=%p)", |
| 422 | + e->options.transport.parent_session_id); |
| 423 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 424 | + assert(false); |
| 425 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 426 | + return; |
| 427 | + } |
| 428 | + index += written; |
416 | 429 | }
|
417 | 430 |
|
418 | 431 | // Source address
|
419 |
| - index += snprintf(message + index, |
420 |
| - sizeof(message) - index, |
421 |
| - " - %d:%d -> ", |
422 |
| - e->connection_info.local.node_id, |
423 |
| - e->connection_info.local.endpoint_id); |
| 432 | + written = snprintf(message + index, |
| 433 | + sizeof(message) - index, |
| 434 | + " - %d:%d -> ", |
| 435 | + e->connection_info.local.node_id, |
| 436 | + e->connection_info.local.endpoint_id); |
| 437 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 438 | + assert(false); |
| 439 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 440 | + return; |
| 441 | + } |
| 442 | + index += written; |
424 | 443 |
|
425 | 444 | // Destination
|
426 | 445 | if (e->connection_info.remote.is_multicast == false) {
|
427 |
| - index += snprintf(message + index, |
428 |
| - sizeof(message) - index, |
429 |
| - " %d:%d - ", |
430 |
| - e->connection_info.remote.node_id, |
431 |
| - e->connection_info.remote.endpoint_id); |
| 446 | + written = snprintf(message + index, |
| 447 | + sizeof(message) - index, |
| 448 | + " %d:%d - ", |
| 449 | + e->connection_info.remote.node_id, |
| 450 | + e->connection_info.remote.endpoint_id); |
| 451 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 452 | + assert(false); |
| 453 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 454 | + return; |
| 455 | + } |
| 456 | + index += written; |
| 457 | + |
432 | 458 | } else {
|
433 |
| - index += snprintf(message + index, |
434 |
| - sizeof(message) - index, |
435 |
| - "Group ID %d (endpoint=%d) - ", |
436 |
| - e->connection_info.remote.multicast_group, |
437 |
| - e->connection_info.remote.endpoint_id); |
| 459 | + written = snprintf(message + index, |
| 460 | + sizeof(message) - index, |
| 461 | + "Group ID %d (endpoint=%d) - ", |
| 462 | + e->connection_info.remote.multicast_group, |
| 463 | + e->connection_info.remote.endpoint_id); |
| 464 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 465 | + assert(false); |
| 466 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 467 | + return; |
| 468 | + } |
| 469 | + index += written; |
438 | 470 | }
|
439 | 471 |
|
440 | 472 | // Encapsulation & payload
|
441 |
| - index += snprintf(message + index, |
442 |
| - sizeof(message) - index, |
443 |
| - "Encapsulation %d - Payload (%d bytes) [", |
444 |
| - e->connection_info.encapsulation, |
445 |
| - e->data_length); |
| 473 | + written = snprintf(message + index, |
| 474 | + sizeof(message) - index, |
| 475 | + "Encapsulation %d - Payload (%d bytes) [", |
| 476 | + e->connection_info.encapsulation, |
| 477 | + e->data_length); |
| 478 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 479 | + assert(false); |
| 480 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 481 | + return; |
| 482 | + } |
| 483 | + index += written; |
446 | 484 |
|
447 | 485 | for (uint16_t i = 0; i < e->data_length; i++) {
|
448 |
| - index += snprintf(message + index, |
449 |
| - sizeof(message) - index, |
450 |
| - "%02X ", |
451 |
| - e->data[i]); |
| 486 | + written |
| 487 | + = snprintf(message + index, sizeof(message) - index, "%02X ", e->data[i]); |
| 488 | + if (written < 0 || written >= static_cast<int>(sizeof(message) - index)) { |
| 489 | + assert(false); |
| 490 | + sl_log_error(LOG_TAG, "Overflow in zwave_tx_queue::simple_log\n"); |
| 491 | + return; |
| 492 | + } |
| 493 | + index += written; |
452 | 494 | }
|
453 | 495 | sl_log_debug(LOG_TAG, "%s] - Tx Queue size: %d\n", message, queue.size());
|
454 | 496 | }
|
|
0 commit comments