Skip to content

Commit

Permalink
AP_InternalError: fix signedness issue with snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Burka authored and peterbarker committed May 22, 2024
1 parent 17083b5 commit 8e399cf
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions libraries/AP_InternalError/AP_InternalError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,19 @@ void AP_InternalError::errors_as_string(uint8_t *buffer, const uint16_t len) con
{
buffer[0] = 0;
uint32_t buffer_used = 0;
const char *format = "%s"; // no comma before the first item
for (uint8_t i=0; i<ARRAY_SIZE(error_bit_descriptions); i++) {
if (buffer_used >= len) {
break;
}
if (internal_errors & (1U<<i)) {
const char *format;
if (buffer_used == 0) {
format = "%s";
} else {
format = ",%s";
}
const size_t written = hal.util->snprintf((char*)&buffer[buffer_used],
const int written = hal.util->snprintf((char*)&buffer[buffer_used],
len-buffer_used,
format,
error_bit_descriptions[i]);
if (written <= 0) {
format = ",%s"; // once we write something, need commas thereafter

if (written < 0) {
break;
}
buffer_used += written;
Expand Down

0 comments on commit 8e399cf

Please sign in to comment.