tools: constify the optarg handling of seats

This shuts up scan-build complaining about memory leaks in libinput
debug-events (needs the right combination of --device option and eventually
triggering usage()) and saves us a bunch of unnecessary allocations.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-02-21 10:28:56 +10:00
parent 2bfbdfaf6b
commit 20cf83789d
6 changed files with 12 additions and 16 deletions

View file

@ -967,7 +967,7 @@ main(int argc, char **argv)
{
struct libinput *li;
enum tools_backend backend = BACKEND_NONE;
char *seat_or_devices[60] = {NULL};
const char *seat_or_devices[60] = {NULL};
size_t ndevices = 0;
bool grab = false;
bool verbose = false;
@ -1024,7 +1024,7 @@ main(int argc, char **argv)
}
backend = BACKEND_DEVICE;
seat_or_devices[ndevices++] = safe_strdup(optarg);
seat_or_devices[ndevices++] = optarg;
break;
case OPT_UDEV:
if (backend == BACKEND_DEVICE ||
@ -1034,7 +1034,7 @@ main(int argc, char **argv)
}
backend = BACKEND_UDEV;
seat_or_devices[0] = safe_strdup(optarg);
seat_or_devices[0] = optarg;
ndevices = 1;
break;
case OPT_GRAB:
@ -1064,12 +1064,11 @@ main(int argc, char **argv)
usage();
return EXIT_INVALID_USAGE;
}
seat_or_devices[ndevices++] = safe_strdup(argv[optind]);
seat_or_devices[ndevices++] = argv[optind];
} while(++optind < argc);
} else if (backend == BACKEND_NONE) {
backend = BACKEND_UDEV;
seat_or_devices[0] = safe_strdup("seat0");
ndevices = 1;
seat_or_devices[0] = "seat0";
}
memset(&act, 0, sizeof(act));
@ -1089,9 +1088,6 @@ main(int argc, char **argv)
if (!li)
return EXIT_FAILURE;
while (ndevices-- > 0)
free(seat_or_devices[ndevices]);
mainloop(li);
libinput_unref(li);

View file

@ -1521,7 +1521,7 @@ main(int argc, char **argv)
struct tools_options options;
struct libinput *li;
enum tools_backend backend = BACKEND_NONE;
char *seat_or_device[2] = {"seat0", NULL};
const char *seat_or_device[2] = {"seat0", NULL};
bool verbose = false;
if (!gtk_init_check(&argc, &argv))

View file

@ -511,7 +511,7 @@ main(int argc, char **argv)
struct context ctx;
struct libinput *li;
enum tools_backend backend = BACKEND_NONE;
char *seat_or_device[2] = {"seat0", NULL};
const char *seat_or_device[2] = {"seat0", NULL};
struct sigaction act;
bool grab = false;

View file

@ -376,7 +376,7 @@ main(int argc, char **argv)
struct libinput *li;
struct libinput_event *ev;
bool grab = false;
char *seat[2] = {"seat0", NULL};
const char *seat[2] = {"seat0", NULL};
/* This is kept for backwards-compatibility with the old
libinput-list-devices */

View file

@ -305,11 +305,11 @@ out:
}
static struct libinput *
tools_open_device(char **paths, bool verbose, bool *grab)
tools_open_device(const char **paths, bool verbose, bool *grab)
{
struct libinput_device *device;
struct libinput *li;
char **p = paths;
const char **p = paths;
li = libinput_path_create_context(&interface, grab);
if (!li) {
@ -348,7 +348,7 @@ tools_setenv_quirks_dir(void)
struct libinput *
tools_open_backend(enum tools_backend which,
char **seat_or_device,
const char **seat_or_device,
bool verbose,
bool *grab)
{

View file

@ -116,7 +116,7 @@ int tools_parse_option(int option,
const char *optarg,
struct tools_options *options);
struct libinput* tools_open_backend(enum tools_backend which,
char **seat_or_devices,
const char **seat_or_devices,
bool verbose,
bool *grab);
void tools_device_apply_config(struct libinput_device *device,