summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Gerecke <jason.gerecke@wacom.com>2022-01-26 12:58:20 -0800
committerPeter Hutterer <peter.hutterer@who-t.net>2022-02-22 10:41:51 +1000
commit869f32c7b98632974f23606d2d706a69e7cc0b69 (patch)
tree3da7b11038055ccf4175d56878e0c4b5eeb77cbc
parent465412be96b8e1967bd21209af54a11f0c7b0cc3 (diff)
downloadxf86-input-wacom-869f32c7b98632974f23606d2d706a69e7cc0b69.tar.gz
Use locally-declared unsigned loop variables to eliminate warnings
We often use the prototypical `int i` loop variable but sometimes we're iterating over a loop with an unsigned bound. This is low-hanging fruit for cleaning up some of the "Wsign-compare" warnings that exist in the driver. While we're at it, take the opportunity to make many of these loops use local declarations -- a feature standardized way back in 1999 alongside other blockbusters like The Matrix. Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
-rw-r--r--src/wcmCommon.c3
-rw-r--r--src/wcmConfig.c3
-rw-r--r--src/wcmFilter.c3
-rw-r--r--src/wcmTouchFilter.c12
-rw-r--r--src/wcmUSB.c21
-rw-r--r--src/wcmValidateDevice.c13
-rw-r--r--tools/tools-shared.c2
-rw-r--r--tools/xsetwacom.c10
8 files changed, 29 insertions, 38 deletions
diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index 280ee23..6e3ee2b 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1758,9 +1758,8 @@ TEST_CASE(test_get_scroll_delta)
{128, 4, 256, AXIS_BITWISE, 5}, {4, 128, 256, AXIS_BITWISE, -5},
{256, 4, 256, AXIS_BITWISE, -4}, {4, 256, 256, AXIS_BITWISE, 4}
};
- int i;
- for (i = 0; i < ARRAY_SIZE(test_table); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(test_table); i++)
{
int delta;
int current, old, wrap, flags;
diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index 780eba6..ed65de8 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -1223,10 +1223,9 @@ TEST_CASE(test_set_type)
TEST_CASE(test_flag_set)
{
- int i;
unsigned int flags = 0;
- for (i = 0; i < sizeof(flags); i++)
+ for (size_t i = 0; i < sizeof(flags); i++)
{
int mask = 1 << i;
flags = 0;
diff --git a/src/wcmFilter.c b/src/wcmFilter.c
index a2f573a..6c9839b 100644
--- a/src/wcmFilter.c
+++ b/src/wcmFilter.c
@@ -484,9 +484,8 @@ TEST_CASE(test_tilt_to_rotation)
{ -156, 987, 70}, { -139, 990, 65}, { -121, 992, 60}, { -104, 994, 55}, { -87, 996, 50},
{ -69, 997, 45}, { -52, 998, 40}, { -34, 999, 35}, { -17, 999, 30},
};
- int i;
- for (i = 0; i < ARRAY_SIZE(rotation_table); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(rotation_table); i++)
{
int rotation;
int x, y;
diff --git a/src/wcmTouchFilter.c b/src/wcmTouchFilter.c
index 642436f..5bf053c 100644
--- a/src/wcmTouchFilter.c
+++ b/src/wcmTouchFilter.c
@@ -58,9 +58,7 @@ static void wcmFingerZoom(WacomDevicePtr priv);
*/
static WacomChannelPtr getContactNumber(WacomCommonPtr common, int num)
{
- int i;
-
- for (i = 0; i < MAX_CHANNELS; i++)
+ for (size_t i = 0; i < MAX_CHANNELS; i++)
{
WacomChannelPtr channel = common->wcmChannel+i;
WacomDeviceState state = channel->valid.state;
@@ -144,9 +142,8 @@ static void
wcmFingerMultitouch(WacomDevicePtr priv, int contact_id) {
Bool lag_mode = priv->common->wcmGestureMode == GESTURE_LAG_MODE;
Bool prox = FALSE;
- int i;
- for (i = 0; i < MAX_CHANNELS; i++) {
+ for (size_t i = 0; i < MAX_CHANNELS; i++) {
WacomChannelPtr channel = priv->common->wcmChannel+i;
WacomDeviceState state = channel->valid.state;
if (state.device_type != TOUCH_ID)
@@ -619,7 +616,7 @@ static void wcmFingerScroll(WacomDevicePtr priv)
WacomDeviceState *start = common->wcmGestureState;
int midPoint_new = 0;
int midPoint_old = 0;
- int i = 0, dist = 0;
+ int dist = 0;
WacomFilterState filterd; /* borrow this struct */
int max_spread = common->wcmGestureParameters.wcmZoomDistance;
int spread;
@@ -667,8 +664,9 @@ static void wcmFingerScroll(WacomDevicePtr priv)
filterd.y[3] = common->wcmGestureState[1].y;
/* scrolling has directions so rotation has to be considered first */
- for (i=0; i<6; i++)
+ for (unsigned int i = 0; i < 6; i++) {
wcmRotateAndScaleCoordinates(priv, &filterd.x[i], &filterd.y[i]);
+ }
/* check vertical direction */
if (common->wcmGestureParameters.wcmScrollDirection == WACOM_VERT_ALLOWED)
diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 5b10ee3..fbe47ae 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -411,7 +411,6 @@ size_t wcmListModels(const char **names, size_t len)
static Bool usbWcmInit(WacomDevicePtr priv)
{
- int i;
struct input_id sID;
WacomCommonPtr common = priv->common;
wcmUSBData *usbdata;
@@ -433,7 +432,7 @@ static Bool usbWcmInit(WacomDevicePtr priv)
usbdata = common->private;
- for (i = 0; i < ARRAY_SIZE(WacomModelDesc); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(WacomModelDesc); i++)
{
if (sID.vendor == WacomModelDesc[i].vendor_id &&
sID.product == WacomModelDesc [i].model_id)
@@ -467,7 +466,7 @@ static Bool usbWcmInit(WacomDevicePtr priv)
/* Find out supported button codes. */
usbdata->npadkeys = 0;
- for (i = 0; i < ARRAY_SIZE(padkey_codes); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(padkey_codes); i++)
if (ISBITSET (common->wcmKeys, padkey_codes [i]))
usbdata->padkey_code [usbdata->npadkeys++] = padkey_codes [i];
@@ -477,15 +476,12 @@ static Bool usbWcmInit(WacomDevicePtr priv)
* If we're wrong, this will over-state the capabilities of the pad
* but that shouldn't actually cause problems.
*/
- for (i = ARRAY_SIZE(mouse_codes) - 1; i > 0; i--)
- if (ISBITSET(common->wcmKeys, mouse_codes[i]))
+ for (size_t i = ARRAY_SIZE(mouse_codes) - 1; i > 0; i--) {
+ if (ISBITSET(common->wcmKeys, mouse_codes[i])) {
+ usbdata->npadkeys = WCM_USB_MAX_MOUSE_BUTTONS;
break;
-
- /* Make sure room for fixed map mouse buttons. This
- * means mappings may overlap with padkey_codes[].
- */
- if (i != 0)
- usbdata->npadkeys = WCM_USB_MAX_MOUSE_BUTTONS;
+ }
+ }
}
/* nbuttons tracks maximum buttons on all tools (stylus/mouse).
@@ -2075,8 +2071,7 @@ static int usbProbeKeys(WacomDevicePtr priv)
TEST_CASE(test_mod_buttons)
{
WacomCommonRec common = {0};
- int i;
- for (i = 0; i < sizeof(int) * 8; i++)
+ for (size_t i = 0; i < sizeof(int) * 8; i++)
{
int buttons = mod_buttons(&common, 0, i, 1);
assert(buttons == (1 << i));
diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c
index baf4bf9..a1a925b 100644
--- a/src/wcmValidateDevice.c
+++ b/src/wcmValidateDevice.c
@@ -142,7 +142,7 @@ static struct
Bool wcmIsAValidType(WacomDevicePtr priv, const char* type)
{
WacomCommonPtr common = priv->common;
- int i, j;
+ size_t i, j;
char* dsource;
Bool user_defined;
@@ -504,18 +504,18 @@ static void wcmHotplugSerials(WacomDevicePtr priv, const char *basename)
void wcmHotplugOthers(WacomDevicePtr priv, const char *basename)
{
- int i, skip = 1;
+ Bool skip = TRUE;
wcmLog(priv, W_INFO, "hotplugging dependent devices.\n");
/* same loop is used to init the first device, if we get here we
* need to start at the second one */
- for (i = 0; i < ARRAY_SIZE(wcmType); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(wcmType); i++)
{
if (wcmIsAValidType(priv, wcmType[i].type))
{
if (skip)
- skip = 0;
+ skip = FALSE;
else
wcmAddHotpluggedDevice(priv, basename, wcmType[i].type, NULL);
}
@@ -523,7 +523,7 @@ void wcmHotplugOthers(WacomDevicePtr priv, const char *basename)
wcmHotplugSerials(priv, basename);
- wcmLog(priv, W_INFO, "hotplugging completed.\n");
+ wcmLog(priv, W_INFO, "hotplugging completed.\n");
}
/**
@@ -538,7 +538,6 @@ void wcmHotplugOthers(WacomDevicePtr priv, const char *basename)
int wcmNeedAutoHotplug(WacomDevicePtr priv, char **type)
{
char *source = wcmOptCheckStr(priv, "_source", NULL);
- int i;
int rc = 0;
if (*type) /* type specified, don't hotplug */
@@ -552,7 +551,7 @@ int wcmNeedAutoHotplug(WacomDevicePtr priv, char **type)
/* no type specified, so we need to pick the first one applicable
* for our device */
- for (i = 0; i < ARRAY_SIZE(wcmType); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(wcmType); i++)
{
if (wcmIsAValidType(priv, wcmType[i].type))
{
diff --git a/tools/tools-shared.c b/tools/tools-shared.c
index d7dc8e1..8ea6d80 100644
--- a/tools/tools-shared.c
+++ b/tools/tools-shared.c
@@ -197,7 +197,7 @@ void memdump(const unsigned char *buffer, int len)
int skip_garbage(unsigned char *buffer, size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < len; i++)
if (buffer[i] & HEADER_BIT)
break;
diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
index 38b1948..6992d75 100644
--- a/tools/xsetwacom.c
+++ b/tools/xsetwacom.c
@@ -1986,7 +1986,6 @@ static int get_actions(Display *dpy, XDevice *dev,
Atom prop, type;
int format;
unsigned long nitems, bytes_after, *data;
- int i;
char buff[1024] = {0};
int last_type;
@@ -2018,7 +2017,7 @@ static int get_actions(Display *dpy, XDevice *dev,
&bytes_after, (unsigned char**)&data);
last_type = 0;
- for (i = 0; i < nitems; i++)
+ for (unsigned int i = 0; i < nitems; i++)
{
unsigned long action = data[i];
int current_type;
@@ -2263,8 +2262,9 @@ static Bool get_mapped_area(Display *dpy, XDevice *dev, int *width, int *height,
/* XI1 stores 32 bit properties (including float) as long,
* regardless of architecture */
- for (size_t i = 0; i < ARRAY_SIZE(matrix); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(matrix); i++) {
matrix[i] = *(float*)(&data[i]);
+ }
TRACE("Current transformation matrix:\n");
TRACE(" [ %f %f %f ]\n", matrix[0], matrix[1], matrix[2]);
@@ -2313,8 +2313,10 @@ static Bool _set_matrix_prop(Display *dpy, XDevice *dev, const float fmatrix[9])
/* XI1 expects 32 bit properties (including float) as long,
* regardless of architecture */
- for (size_t i = 0; i < ARRAY_SIZE(matrix); i++)
+
+ for (size_t i = 0; i < ARRAY_SIZE(matrix); i++) {
*(float*)(matrix + i) = fmatrix[i];
+ }
XGetDeviceProperty(dpy, dev, matrix_prop, 0, 9, False,
AnyPropertyType, &type, &format, &nitems,