From 624d384ac7c0b7972c3f31d974ead47b3207bbb2 Mon Sep 17 00:00:00 2001 From: Balduin Date: Mon, 30 Nov 2026 14:10:53 +0100 Subject: [PATCH] fix(px4_log): keep the newline on truncated colored console lines The color reset and newline were written with a size that excluded the byte buf reserves for the terminating NUL, so snprintf dropped the newline whenever a line hit the length limit and the next log line was printed on the same line. Assisted-by: Claude:claude-opus-5-5 --- platforms/common/px4_log.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/common/px4_log.cpp b/platforms/common/px4_log.cpp index 3c94ee1a4eb..db70ba46771 100644 --- a/platforms/common/px4_log.cpp +++ b/platforms/common/px4_log.cpp @@ -138,7 +138,7 @@ __EXPORT void px4_log_modulename_va(int level, const char *module_name, const ch if (use_color) { // always reset color const ssize_t sz = math::min(pos, max_length - (ssize_t)strlen(PX4_ANSI_COLOR_RESET) - (ssize_t)1); - pos += snprintf(buf + sz, math::max(max_length - sz, (ssize_t)0), "%s\n", PX4_ANSI_COLOR_RESET); + pos += snprintf(buf + sz, math::max(max_length + 1 - sz, (ssize_t)0), "%s\n", PX4_ANSI_COLOR_RESET); } else #endif // PX4_LOG_COLORIZED_OUTPUT