mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 22:58:11 +02:00
tools/debug-tablet: switch an snprintf to strvs
Less having to think about snprintf's buffer correctness Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1453>
This commit is contained in:
parent
166201d9fc
commit
1c4040ffa3
1 changed files with 9 additions and 7 deletions
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include "util-input-event.h"
|
#include "util-input-event.h"
|
||||||
#include "util-macros.h"
|
#include "util-macros.h"
|
||||||
|
#include "util-strings.h"
|
||||||
|
|
||||||
#include "shared.h"
|
#include "shared.h"
|
||||||
|
|
||||||
|
|
@ -91,19 +92,20 @@ print_line(const char *format, ...)
|
||||||
static void
|
static void
|
||||||
print_buttons(struct context *ctx, unsigned int *buttons, size_t sz)
|
print_buttons(struct context *ctx, unsigned int *buttons, size_t sz)
|
||||||
{
|
{
|
||||||
char buf[256] = { 0 };
|
_autostrvfree_ char **strv = NULL;
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < sz; i++) {
|
for (size_t i = 0; i < sz; i++) {
|
||||||
const char *name;
|
|
||||||
|
|
||||||
if (buttons[i] == 0)
|
if (buttons[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
name = libevdev_event_code_get_name(EV_KEY, buttons[i]);
|
strv = strv_append_printf(
|
||||||
len += snprintf(&buf[len], sizeof(buf) - len, "%s ", name);
|
strv,
|
||||||
|
"%s",
|
||||||
|
libevdev_event_code_get_name(EV_KEY, buttons[i]));
|
||||||
}
|
}
|
||||||
print_line(" buttons: %s", buf);
|
|
||||||
|
_autofree_ char *btnstr = strv_join(strv, " ");
|
||||||
|
print_line(" buttons: %s", btnstr ? btnstr : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue