aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/input-manager.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-19 04:57:42 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-19 04:57:42 -0500
commit730af5e721f04cf12b613341e00b44a93f3397c6 (patch)
treefac2524c65e64a2267ac05ffea390ecb038397f4 /sway/input/input-manager.c
parentdocument fallback seat (diff)
downloadsway-730af5e721f04cf12b613341e00b44a93f3397c6.tar.gz
sway-730af5e721f04cf12b613341e00b44a93f3397c6.tar.zst
sway-730af5e721f04cf12b613341e00b44a93f3397c6.zip
use snprintf to get identifier len
Diffstat (limited to 'sway/input/input-manager.c')
-rw-r--r--sway/input/input-manager.c16
1 files changed, 2 insertions, 14 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index 52da8f5e..b20b7b7e 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -34,13 +34,6 @@ static struct sway_seat *input_manager_get_seat(
34 return sway_seat_create(input, seat_name); 34 return sway_seat_create(input, seat_name);
35} 35}
36 36
37static inline int strlen_num(int num) {
38 if (num == 0) {
39 return 2;
40 }
41 return (int)((ceil(log10(abs(num)))+2));
42}
43
44static char *get_device_identifier(struct wlr_input_device *device) { 37static char *get_device_identifier(struct wlr_input_device *device) {
45 int vendor = device->vendor; 38 int vendor = device->vendor;
46 int product = device->product; 39 int product = device->product;
@@ -54,19 +47,14 @@ static char *get_device_identifier(struct wlr_input_device *device) {
54 } 47 }
55 } 48 }
56 49
57 int len = 50 const char *fmt = "%d:%d:%s";
58 (strlen(name) + 51 int len = snprintf(NULL, 0, fmt, vendor, product, name) + 1;
59 strlen_num(device->vendor) +
60 strlen_num(device->product) +
61 3) * sizeof(char);
62
63 char *identifier = malloc(len); 52 char *identifier = malloc(len);
64 if (!identifier) { 53 if (!identifier) {
65 sway_log(L_ERROR, "Unable to allocate unique input device name"); 54 sway_log(L_ERROR, "Unable to allocate unique input device name");
66 return NULL; 55 return NULL;
67 } 56 }
68 57
69 const char *fmt = "%d:%d:%s";
70 snprintf(identifier, len, fmt, vendor, product, name); 58 snprintf(identifier, len, fmt, vendor, product, name);
71 free(name); 59 free(name);
72 return identifier; 60 return identifier;