AP_InternalError: fix signedness issue with snprintf

This commit is contained in:
Alex Burka 2020-09-01 00:27:03 -04:00 committed by Peter Barker
parent 17083b54f8
commit 8e399cffbe

View File

@ -85,22 +85,19 @@ void AP_InternalError::errors_as_string(uint8_t *buffer, const uint16_t len) con
{ {
buffer[0] = 0; buffer[0] = 0;
uint32_t buffer_used = 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++) { for (uint8_t i=0; i<ARRAY_SIZE(error_bit_descriptions); i++) {
if (buffer_used >= len) { if (buffer_used >= len) {
break; break;
} }
if (internal_errors & (1U<<i)) { if (internal_errors & (1U<<i)) {
const char *format; const int written = hal.util->snprintf((char*)&buffer[buffer_used],
if (buffer_used == 0) {
format = "%s";
} else {
format = ",%s";
}
const size_t written = hal.util->snprintf((char*)&buffer[buffer_used],
len-buffer_used, len-buffer_used,
format, format,
error_bit_descriptions[i]); error_bit_descriptions[i]);
if (written <= 0) { format = ",%s"; // once we write something, need commas thereafter
if (written < 0) {
break; break;
} }
buffer_used += written; buffer_used += written;