aboutsummaryrefslogtreecommitdiffstats
path: root/test-visual.c
diff options
context:
space:
mode:
Diffstat (limited to 'test-visual.c')
-rw-r--r--test-visual.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/test-visual.c b/test-visual.c
index 58ba20d..316299c 100644
--- a/test-visual.c
+++ b/test-visual.c
@@ -24,12 +24,21 @@ draw_axis(char buffer[], const struct abs_axis *axis, size_t len)
/* TODO axis->value can actually be out of bounds */
char value_buf[sizeof(intmax_t) * 3 + 2];
size_t width, x, value_len;
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
sprintf(buffer, "%-*ji%ji", (int)(len - axis->max_len), axis->min, axis->max);
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
width = len - axis->max_len - axis->min_len;
value_len = (size_t)sprintf(value_buf, "%ji", axis->value);
x = axis->max_len + (width - value_len) / 2;
memcpy(&buffer[x], value_buf, value_len);
- x = ((axis->value - axis->min) * len + (axis->max - axis->min) / 2) / (axis->max - axis->min);
+ x = (size_t)(axis->value - axis->min) * len;
+ x += (size_t)(axis->max - axis->min) / 2;
+ x /= (size_t)(axis->max - axis->min);
memmove(&buffer[x + sizeof("\033[m") - 1], &buffer[x], len - x);
memcpy(&buffer[x], "\033[m", sizeof("\033[m") - 1);
return buffer;
@@ -129,13 +138,13 @@ main(int argc, char *argv[])
x = i % button_columns;
y = i / button_columns;
printf("\033[%zu;%zuH%s¿%s?\033[m", y + 1, x * (max_button_name_len + 3) + 1,
- libgamepad_get_button_is_pressed(&gamepad, (unsigned int)gamepad.buttons[i]) ? "\033[7m" : "\033[m",
+ libgamepad_get_button_is_pressed(&gamepad, gamepad.buttons[i]) ? "\033[7m" : "\033[m",
button_names[i]);
}
printf("\033[%zuH", button_rows + 1);
for (i = 0; i < gamepad.nabsolute_axes; i++) {
printf("\n%-*s ¿\033[7m%s?", (int)max_abs_axis_name_len,
- libgamepad_get_absolute_axis_name((unsigned int)gamepad.absolute_axes[i]),
+ libgamepad_get_absolute_axis_name(gamepad.absolute_axes[i]),
draw_axis(buffer, &abs_axes[i], axis_len));
}