mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 02:26:16 +00:00
u/logging: Use truncating snprintf utility for JSON log
When using the JSON logging mode, truncate log strings to ensure they fit in the allocated message buffer Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2373>
This commit is contained in:
parent
efa6c5d149
commit
e076de071a
|
@ -339,7 +339,7 @@ log_as_json(const char *file, const char *func, enum u_logging_level level, cons
|
||||||
|
|
||||||
// Add message.
|
// Add message.
|
||||||
char msg_buf[LOG_BUFFER_SIZE];
|
char msg_buf[LOG_BUFFER_SIZE];
|
||||||
vsprintf(msg_buf, format, args);
|
u_truncate_vsnprintf(msg_buf, LOG_BUFFER_SIZE, format, args);
|
||||||
cJSON_AddItemToObject(root, "message", cJSON_CreateString(msg_buf));
|
cJSON_AddItemToObject(root, "message", cJSON_CreateString(msg_buf));
|
||||||
|
|
||||||
// Get string and print to stderr.
|
// Get string and print to stderr.
|
||||||
|
|
Loading…
Reference in a new issue