core: avoid use of C array as buffer in Log_root

This commit is contained in:
Norman Feske 2020-01-02 21:14:52 +01:00 committed by Emery Hemingway
parent b20ca5f254
commit 7c4568fb5a
2 changed files with 6 additions and 15 deletions

View File

@ -30,12 +30,7 @@ namespace Genode {
*/ */
Log_session_component *_create_session(const char *args) override Log_session_component *_create_session(const char *args) override
{ {
char label_buf[Log_session_component::LABEL_LEN]; return new (md_alloc()) Log_session_component(label_from_args(args));
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);
} }
public: public:

View File

@ -17,27 +17,23 @@
#include <util/string.h> #include <util/string.h>
#include <base/log.h> #include <base/log.h>
#include <base/rpc_server.h> #include <base/rpc_server.h>
#include <base/session_label.h>
#include <log_session/log_session.h> #include <log_session/log_session.h>
namespace Genode { namespace Genode {
class Log_session_component : public Rpc_object<Log_session> class Log_session_component : public Rpc_object<Log_session>
{ {
public:
enum { LABEL_LEN = 128 };
private: private:
char _label[LABEL_LEN]; Session_label const _label;
public: public:
/** /**
* Constructor * Constructor
*/ */
Log_session_component(const char *label) { Log_session_component(Session_label const &label) : _label(label) { }
strncpy(_label, label, sizeof(_label)); }
/***************** /*****************
@ -61,14 +57,14 @@ namespace Genode {
if (string[i] == '\n') { if (string[i] == '\n') {
memcpy(buf, string + from_i, i - from_i); memcpy(buf, string + from_i, i - from_i);
buf[i - from_i] = 0; buf[i - from_i] = 0;
log("[", Cstring(_label), "] ", Cstring(buf)); log("[", _label, "] ", Cstring(buf));
from_i = i + 1; from_i = i + 1;
} }
} }
/* if last character of string was not a line break, add one */ /* if last character of string was not a line break, add one */
if (from_i < len) if (from_i < len)
log("[", Cstring(_label), "] ", Cstring(string + from_i)); log("[", _label, "] ", Cstring(string + from_i));
return len; return len;
} }