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.
*/
if (id) {
char buf[128];
Genode::snprintf(buf, sizeof(buf), "%d", id);
_gui.enqueue<Command::Title>(_handle, Genode::Cstring(buf));
}
if (id)
_gui.enqueue<Command::Title>(_handle,
Genode::String<128>(id).string());
}
~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.
*/
if (id) {
char buf[128];
Genode::snprintf(buf, sizeof(buf), "%d", id);
_gui.enqueue<Command::Title>(_handle, Genode::Cstring(buf));
}
if (id)
_gui.enqueue<Command::Title>(_handle,
Genode::String<128>(id).string());
}
View_handle _create_remote_view(Gui::Session_client &remote_gui)

View File

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

View File

@ -12,7 +12,7 @@
*/
/* Genode includes */
#include <base/snprintf.h>
#include <util/string.h>
/* local includes */
#include "cpu_session_component.h"
@ -32,28 +32,14 @@ Cpu_sampler::Cpu_thread_component::Cpu_thread_component(
addr_t utcb,
char const *thread_name,
unsigned int thread_id)
: _cpu_session_component(cpu_session_component), _env(env),
_md_alloc(md_alloc),
_parent_cpu_thread(
_cpu_session_component.parent_cpu_session().create_thread(pd,
name,
affinity,
weight,
utcb))
:
_cpu_session_component(cpu_session_component), _env(env), _md_alloc(md_alloc),
_parent_cpu_thread(
_cpu_session_component.parent_cpu_session()
.create_thread(pd, name, affinity, weight, utcb)),
_label(_cpu_session_component.session_label().string(), " -> ", thread_name),
_log_session_label("samples -> ", _label, ".", thread_id)
{
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);
}
@ -121,21 +107,13 @@ void Cpu_sampler::Cpu_thread_component::flush()
_log.construct(_env, _log_session_label);
/* number of hex characters + newline + '\0' */
enum { SAMPLE_STRING_SIZE = 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";
using Sample = String<2 * sizeof(addr_t) + 1 + 1>;
for (unsigned int i = 0; i < _sample_buf_index; i++) {
snprintf(sample_string, SAMPLE_STRING_SIZE, format_string,
_sample_buf[i]);
_log->write(sample_string);
Sample const sample(Hex(_sample_buf[i], Hex::OMIT_PREFIX, Hex::PAD), "\n");
_log->write(sample.string());
}
_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
{
using namespace Genode;
/*
* Append label separator to match selectors with a trailing
* 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];
Genode::snprintf(label, sizeof(label), "%s ->", _session_label.string());
return Genode::strcmp(label, selector,
Genode::strlen(selector)) == 0;
String<Session_label::capacity() + 4> const label(_session_label, " ->");
return strcmp(label.string(), selector, strlen(selector)) == 0;
}
void request_resize(Area size)

View File

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