From 8e399cffbe43af8ada4065f196c96f25f7f1133b Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Tue, 1 Sep 2020 00:27:03 -0400 Subject: [PATCH] AP_InternalError: fix signedness issue with snprintf --- libraries/AP_InternalError/AP_InternalError.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/AP_InternalError/AP_InternalError.cpp b/libraries/AP_InternalError/AP_InternalError.cpp index bc505804a8..0f23b2d1d4 100644 --- a/libraries/AP_InternalError/AP_InternalError.cpp +++ b/libraries/AP_InternalError/AP_InternalError.cpp @@ -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= len) { break; } if (internal_errors & (1U<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;