Browse Source

tests/ioctl_evdev-success: rewrite ABS_MT check

Use null-terminating array instead of providing array size in the first
element.

* tests/ioctl_evdev-success.c (print_mtslots, main): Update
mtslots_str/invalid_mtslot_str array usage.
Eugene Syromyatnikov 3 months ago
parent
commit
d9c21e2c73
1 changed files with 10 additions and 13 deletions
  1. 10
    13
      tests/ioctl_evdev-success.c

+ 10
- 13
tests/ioctl_evdev-success.c View File

@@ -96,19 +96,18 @@ print_input_id(long rc, const void *ptr, const void *arg)
96 96
 static void
97 97
 print_mtslots(long rc, const void *ptr, const void *arg)
98 98
 {
99
-	const int *buffer = ptr;
99
+	const unsigned int *buffer = ptr;
100 100
 	const char * const * str = arg;
101
-	int num = atoi(*(str + 1));
102 101
 
103 102
 	if (rc < 0) {
104 103
 		printf("%p", buffer);
105 104
 		return;
106 105
 	}
107 106
 
108
-	printf("{code=%s", *str);
107
+	printf("{code=%s", sprintxlat(*str, *buffer, NULL));
109 108
 	printf(", values=[");
110
-	for (unsigned int i = 1; i <= (unsigned) num; i++)
111
-		printf("%s%s", i > 1 ? ", " : "", *(str + i + 1));
109
+	for (unsigned int i = 1; str[i]; i++)
110
+		printf("%s%s", i > 1 ? ", " : "", str[i]);
112 111
 	printf("]}");
113 112
 }
114 113
 # endif
@@ -181,16 +180,14 @@ main(int argc, char **argv)
181 180
 	TAIL_ALLOC_OBJECT_CONST_PTR(int, bad_addr_slot);
182 181
 
183 182
 # ifdef EVIOCGMTSLOTS
184
-	int mtslots[] = { ABS_MT_SLOT, 1, 3 };
185
-	/* we use the second element to indicate the number of values */
186
-	/* mtslots_str[1] is "2" so the number of values is 2 */
187
-	const char *mtslots_str[] = { "ABS_MT_SLOT", "2", "1", "3" };
183
+	static const unsigned int mtslots[] = { ABS_MT_SLOT, 1, 3 };
184
+	static const char * const mtslots_str[] = {
185
+		"ABS_MT_SLOT", "1", "3", NULL };
188 186
 
189 187
 	/* invalid flag */
190
-	int invalid_mtslot[] = { -1, 1 };
191
-	char invalid_str[4096];
192
-	snprintf(invalid_str, sizeof(invalid_str), "%#x /* ABS_MT_??? */", invalid_mtslot[0]);
193
-	const char *invalid_mtslot_str[] = { invalid_str, "1", "1" };
188
+	static const unsigned int invalid_mtslot[] = { -1, 1 };
189
+	static const char * const invalid_mtslot_str[] = {
190
+		"0xffffffff /* ABS_MT_??? */", "1", NULL };
194 191
 # endif
195 192
 
196 193
 	enum { ULONG_BIT = sizeof(unsigned long) * 8 };

Loading…
Cancel
Save