aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <jaylink-dev@marcschink.de>2019-09-03 10:16:31 +0200
committerMarc Schink <jaylink-dev@marcschink.de>2019-10-03 12:03:39 +0200
commitcfccbc9d6763733f1d14dff3c2dc5b75aaef136b (patch)
treef733ee43299f207ba5f58e2c3910f1e55ef16898
parentf6209d71a0f96c5597bf7a38426ab9f55f14538c (diff)
Declare variables in for-loops (C99-style)HEADmaster
Signed-off-by: Marc Schink <jaylink-dev@marcschink.de>
-rw-r--r--libjaylink/device.c23
-rw-r--r--libjaylink/discovery_usb.c6
-rw-r--r--libjaylink/transport_tcp.c3
-rw-r--r--libjaylink/transport_usb.c5
4 files changed, 13 insertions, 24 deletions
diff --git a/libjaylink/device.c b/libjaylink/device.c
index 3a5f7d2..5a87fcf 100644
--- a/libjaylink/device.c
+++ b/libjaylink/device.c
@@ -141,7 +141,6 @@ JAYLINK_API int jaylink_get_devices(struct jaylink_context *ctx,
struct list *item;
struct jaylink_device **tmp;
struct jaylink_device *dev;
- size_t i;
if (!ctx || !devs)
return JAYLINK_ERR_ARG;
@@ -156,7 +155,7 @@ JAYLINK_API int jaylink_get_devices(struct jaylink_context *ctx,
item = ctx->discovered_devs;
- for (i = 0; i < num; i++) {
+ for (size_t i = 0; i < num; i++) {
dev = (struct jaylink_device *)item->data;
tmp[i] = jaylink_ref_device(dev);
item = item->next;
@@ -183,13 +182,11 @@ JAYLINK_API int jaylink_get_devices(struct jaylink_context *ctx,
*/
JAYLINK_API void jaylink_free_devices(struct jaylink_device **devs, bool unref)
{
- size_t i;
-
if (!devs)
return;
if (unref) {
- for (i = 0; devs[i]; i++)
+ for (size_t i = 0; devs[i]; i++)
jaylink_unref_device(devs[i]);
}
@@ -807,7 +804,6 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
int ret;
struct jaylink_context *ctx;
uint8_t buf[5];
- unsigned int i;
unsigned int num;
unsigned int length;
@@ -817,7 +813,7 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
ctx = devh->dev->ctx;
num = 0;
- for (i = 0; i < 32; i++) {
+ for (unsigned int i = 0; i < 32; i++) {
if (mask & (1 << i))
num++;
}
@@ -851,7 +847,7 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
return ret;
}
- for (i = 0; i < num; i++)
+ for (unsigned int i = 0; i < num; i++)
info[i] = buffer_get_u32((uint8_t *)info,
i * sizeof(uint32_t));
@@ -887,7 +883,6 @@ JAYLINK_API int jaylink_get_counters(struct jaylink_device_handle *devh,
int ret;
struct jaylink_context *ctx;
uint8_t buf[5];
- unsigned int i;
unsigned int num;
unsigned int length;
@@ -897,7 +892,7 @@ JAYLINK_API int jaylink_get_counters(struct jaylink_device_handle *devh,
ctx = devh->dev->ctx;
num = 0;
- for (i = 0; i < 32; i++) {
+ for (unsigned int i = 0; i < 32; i++) {
if (mask & (1 << i))
num++;
}
@@ -930,7 +925,7 @@ JAYLINK_API int jaylink_get_counters(struct jaylink_device_handle *devh,
return ret;
}
- for (i = 0; i < num; i++)
+ for (unsigned int i = 0; i < num; i++)
values[i] = buffer_get_u32((uint8_t *)values,
i * sizeof(uint32_t));
@@ -1387,13 +1382,12 @@ JAYLINK_API int jaylink_write_raw_config(struct jaylink_device_handle *devh,
static void parse_conn_table(struct jaylink_connection *conns,
const uint8_t *buffer, uint16_t num, uint16_t entry_size)
{
- unsigned int i;
size_t offset;
struct in_addr in;
offset = 0;
- for (i = 0; i < num; i++) {
+ for (unsigned int i = 0; i < num; i++) {
conns[i].pid = buffer_get_u32(buffer, offset);
in.s_addr = buffer_get_u32(buffer, offset + 4);
@@ -1463,7 +1457,6 @@ static bool _inet_pton(const char *str, struct in_addr *in)
* struct jaylink_connection conns[JAYLINK_MAX_CONNECTIONS];
* bool found_handle;
* size_t count;
- * size_t i;
*
* conn->handle = 0;
* conn->pid = 0;
@@ -1481,7 +1474,7 @@ static bool _inet_pton(const char *str, struct in_addr *in)
*
* found_handle = false;
*
- * for (i = 0; i < count; i++) {
+ * for (size_t i = 0; i < count; i++) {
* if (conns[i].handle == conn->handle) {
* found_handle = true;
* break;
diff --git a/libjaylink/discovery_usb.c b/libjaylink/discovery_usb.c
index fe7b045..5082fc2 100644
--- a/libjaylink/discovery_usb.c
+++ b/libjaylink/discovery_usb.c
@@ -138,7 +138,6 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx,
uint32_t serial_number;
bool valid_serial_number;
bool found_device;
- size_t i;
ret = libusb_get_device_descriptor(usb_dev, &desc);
@@ -153,7 +152,7 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx,
found_device = false;
- for (i = 0; i < sizeof(pids) / sizeof(pids[0]); i++) {
+ for (size_t i = 0; i < sizeof(pids) / sizeof(pids[0]); i++) {
if (pids[i][0] == desc.idProduct) {
found_device = true;
usb_address = pids[i][1];
@@ -249,7 +248,6 @@ JAYLINK_PRIV int discovery_usb_scan(struct jaylink_context *ctx)
struct libusb_device **devs;
struct jaylink_device *dev;
size_t num;
- size_t i;
ret = libusb_get_device_list(ctx->usb_ctx, &devs);
@@ -265,7 +263,7 @@ JAYLINK_PRIV int discovery_usb_scan(struct jaylink_context *ctx)
num = 0;
- for (i = 0; devs[i]; i++) {
+ for (size_t i = 0; devs[i]; i++) {
dev = probe_device(ctx, devs[i]);
if (!dev)
diff --git a/libjaylink/transport_tcp.c b/libjaylink/transport_tcp.c
index 7e10179..f84b105 100644
--- a/libjaylink/transport_tcp.c
+++ b/libjaylink/transport_tcp.c
@@ -231,7 +231,6 @@ JAYLINK_PRIV int transport_tcp_open(struct jaylink_device_handle *devh)
struct jaylink_device *dev;
struct addrinfo hints;
struct addrinfo *info;
- struct addrinfo *rp;
int sock;
dev = devh->dev;
@@ -262,7 +261,7 @@ JAYLINK_PRIV int transport_tcp_open(struct jaylink_device_handle *devh)
sock = -1;
- for (rp = info; rp != NULL; rp = rp->ai_next) {
+ for (struct addrinfo *rp = info; rp != NULL; rp = rp->ai_next) {
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock < 0)
diff --git a/libjaylink/transport_usb.c b/libjaylink/transport_usb.c
index dfe9eac..ce84b1c 100644
--- a/libjaylink/transport_usb.c
+++ b/libjaylink/transport_usb.c
@@ -54,7 +54,6 @@ static int initialize_handle(struct jaylink_device_handle *devh)
bool found_interface;
bool found_endpoint_in;
bool found_endpoint_out;
- uint8_t i;
ctx = devh->dev->ctx;
devh->interface_number = 0;
@@ -73,7 +72,7 @@ static int initialize_handle(struct jaylink_device_handle *devh)
found_interface = false;
- for (i = 0; i < config->bNumInterfaces; i++) {
+ for (uint8_t i = 0; i < config->bNumInterfaces; i++) {
interface = &config->interface[i];
desc = &interface->altsetting[0];
@@ -100,7 +99,7 @@ static int initialize_handle(struct jaylink_device_handle *devh)
found_endpoint_in = false;
found_endpoint_out = false;
- for (i = 0; i < desc->bNumEndpoints; i++) {
+ for (uint8_t i = 0; i < desc->bNumEndpoints; i++) {
epdesc = &desc->endpoint[i];
if (epdesc->bEndpointAddress & LIBUSB_ENDPOINT_IN) {