mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 22:40:27 +08:00
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
This commit is contained in:
1 parent
70c74cb794
commit
624d384ac7
1 file changed
+1
-1
@@ -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
|
||||
|
||||
Reference in new issue
Block a user