gems: remove use of format strings

Issue #2064
This commit is contained in:
Norman Feske 2023-03-06 12:06:44 +01:00 committed by Christian Helmuth
parent ecd0066e80
commit 36c00cc294
6 changed files with 24 additions and 54 deletions

View File

@ -52,12 +52,9 @@ class Decorator::Window : public Window_base
/* /*
* We supply the window ID as label for the anchor view. * We supply the window ID as label for the anchor view.
*/ */
if (id) { if (id)
char buf[128]; _gui.enqueue<Command::Title>(_handle,
Genode::snprintf(buf, sizeof(buf), "%d", id); Genode::String<128>(id).string());
_gui.enqueue<Command::Title>(_handle, Genode::Cstring(buf));
}
} }
~Gui_view() ~Gui_view()

View File

@ -160,12 +160,9 @@ class Decorator::Window : public Window_base, public Animator::Item
/* /*
* We supply the window ID as label for the anchor view. * We supply the window ID as label for the anchor view.
*/ */
if (id) { if (id)
char buf[128]; _gui.enqueue<Command::Title>(_handle,
Genode::snprintf(buf, sizeof(buf), "%d", id); Genode::String<128>(id).string());
_gui.enqueue<Command::Title>(_handle, Genode::Cstring(buf));
}
} }
View_handle _create_remote_view(Gui::Session_client &remote_gui) View_handle _create_remote_view(Gui::Session_client &remote_gui)

View File

@ -14,7 +14,6 @@
#ifndef _SESSION_LABEL_H_ #ifndef _SESSION_LABEL_H_
#define _SESSION_LABEL_H_ #define _SESSION_LABEL_H_
#include <base/snprintf.h>
#include <util/arg_string.h> #include <util/arg_string.h>
#include <util/string.h> #include <util/string.h>

View File

@ -12,7 +12,7 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <base/snprintf.h> #include <util/string.h>
/* local includes */ /* local includes */
#include "cpu_session_component.h" #include "cpu_session_component.h"
@ -32,28 +32,14 @@ Cpu_sampler::Cpu_thread_component::Cpu_thread_component(
addr_t utcb, addr_t utcb,
char const *thread_name, char const *thread_name,
unsigned int thread_id) unsigned int thread_id)
: _cpu_session_component(cpu_session_component), _env(env), :
_md_alloc(md_alloc), _cpu_session_component(cpu_session_component), _env(env), _md_alloc(md_alloc),
_parent_cpu_thread( _parent_cpu_thread(
_cpu_session_component.parent_cpu_session().create_thread(pd, _cpu_session_component.parent_cpu_session()
name, .create_thread(pd, name, affinity, weight, utcb)),
affinity, _label(_cpu_session_component.session_label().string(), " -> ", thread_name),
weight, _log_session_label("samples -> ", _label, ".", thread_id)
utcb))
{ {
char label_buf[Session_label::size()];
snprintf(label_buf, sizeof(label_buf), "%s -> %s",
_cpu_session_component.session_label().string(),
thread_name);
_label = Session_label(label_buf);
snprintf(label_buf, sizeof(label_buf), "samples -> %s.%u",
_label.string(), thread_id);
_log_session_label = Session_label(label_buf);
_cpu_session_component.thread_ep().manage(this); _cpu_session_component.thread_ep().manage(this);
} }
@ -121,21 +107,13 @@ void Cpu_sampler::Cpu_thread_component::flush()
_log.construct(_env, _log_session_label); _log.construct(_env, _log_session_label);
/* number of hex characters + newline + '\0' */ /* number of hex characters + newline + '\0' */
enum { SAMPLE_STRING_SIZE = 2 * sizeof(addr_t) + 1 + 1 }; using Sample = String<2 * sizeof(addr_t) + 1 + 1>;
char sample_string[SAMPLE_STRING_SIZE];
char const *format_string;
if (sizeof(addr_t) == 8)
format_string = "%16lX\n";
else
format_string = "%8X\n";
for (unsigned int i = 0; i < _sample_buf_index; i++) { for (unsigned int i = 0; i < _sample_buf_index; i++) {
snprintf(sample_string, SAMPLE_STRING_SIZE, format_string,
_sample_buf[i]); Sample const sample(Hex(_sample_buf[i], Hex::OMIT_PREFIX, Hex::PAD), "\n");
_log->write(sample_string);
_log->write(sample.string());
} }
_sample_buf_index = 0; _sample_buf_index = 0;

View File

@ -883,16 +883,16 @@ class Wm::Gui::Session_component : public Rpc_object<Gui::Session>,
bool matches_session_label(char const *selector) const bool matches_session_label(char const *selector) const
{ {
using namespace Genode;
/* /*
* Append label separator to match selectors with a trailing * Append label separator to match selectors with a trailing
* separator. * separator.
* *
* The code originates from nitpicker's 'session.h'. * The code snippet originates from nitpicker's 'gui_session.h'.
*/ */
char label[Genode::Session_label::capacity() + 4]; String<Session_label::capacity() + 4> const label(_session_label, " ->");
Genode::snprintf(label, sizeof(label), "%s ->", _session_label.string()); return strcmp(label.string(), selector, strlen(selector)) == 0;
return Genode::strcmp(label, selector,
Genode::strlen(selector)) == 0;
} }
void request_resize(Area size) void request_resize(Area size)

View File

@ -19,7 +19,6 @@
#include <util/xml_generator.h> #include <util/xml_generator.h>
#include <util/list_model.h> #include <util/list_model.h>
#include <gui_session/client.h> #include <gui_session/client.h>
#include <base/snprintf.h>
/* decorator includes */ /* decorator includes */
#include <decorator/types.h> #include <decorator/types.h>