From bbfc092a31f912c26b4f604f8a0a9a3a6531f4d7 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 2 Jan 2020 21:14:52 +0100 Subject: [PATCH] core: avoid use of C array as buffer in Log_root --- repos/base/src/core/include/log_root.h | 7 +------ .../base/src/core/include/log_session_component.h | 14 +++++--------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/repos/base/src/core/include/log_root.h b/repos/base/src/core/include/log_root.h index db98ebfc5b..085c6053f9 100644 --- a/repos/base/src/core/include/log_root.h +++ b/repos/base/src/core/include/log_root.h @@ -30,12 +30,7 @@ namespace Genode { */ Log_session_component *_create_session(const char *args) override { - char label_buf[Log_session_component::LABEL_LEN]; - - Arg label_arg = Arg_string::find_arg(args, "label"); - label_arg.string(label_buf, sizeof(label_buf), ""); - - return new (md_alloc()) Log_session_component(label_buf); + return new (md_alloc()) Log_session_component(label_from_args(args)); } public: diff --git a/repos/base/src/core/include/log_session_component.h b/repos/base/src/core/include/log_session_component.h index 7b6ddab815..1e7ec9d029 100644 --- a/repos/base/src/core/include/log_session_component.h +++ b/repos/base/src/core/include/log_session_component.h @@ -17,27 +17,23 @@ #include #include #include +#include #include namespace Genode { class Log_session_component : public Rpc_object { - public: - - enum { LABEL_LEN = 128 }; - private: - char _label[LABEL_LEN]; + Session_label const _label; public: /** * Constructor */ - Log_session_component(const char *label) { - strncpy(_label, label, sizeof(_label)); } + Log_session_component(Session_label const &label) : _label(label) { } /***************** @@ -61,14 +57,14 @@ namespace Genode { if (string[i] == '\n') { memcpy(buf, string + from_i, i - from_i); buf[i - from_i] = 0; - log("[", Cstring(_label), "] ", Cstring(buf)); + log("[", _label, "] ", Cstring(buf)); from_i = i + 1; } } /* if last character of string was not a line break, add one */ if (from_i < len) - log("[", Cstring(_label), "] ", Cstring(string + from_i)); + log("[", _label, "] ", Cstring(string + from_i)); return len; }