Skip to content

Commit

Permalink
linux: Avoid a number of -Wconversion warnings
Browse files Browse the repository at this point in the history
Add some explicit casts, and avoid some dubious recycling of
the same helper variable for completely different purposes.

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed May 12, 2024
1 parent 9305577 commit 6de7a80
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions libusb/os/linux_usbfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,13 @@ int linux_get_device_address(struct libusb_context *ctx, int detached,
if (!dev_node && fd >= 0) {
char *fd_path = alloca(PATH_MAX);
char proc_path[32];
ssize_t llen;

/* try to retrieve the device node from fd */
snprintf(proc_path, sizeof(proc_path), "/proc/self/fd/%d", fd);
r = readlink(proc_path, fd_path, PATH_MAX - 1);
if (r > 0) {
fd_path[r] = '\0';
llen = readlink(proc_path, fd_path, PATH_MAX - 1);
if (llen > 0) {
fd_path[llen] = '\0';
dev_node = fd_path;
}
}
Expand Down Expand Up @@ -822,7 +823,7 @@ static int op_get_active_config_descriptor(struct libusb_device *dev,

len = MIN(len, (size_t)r);
memcpy(buffer, config_desc, len);
return len;
return (int)len;
}

static int op_get_config_descriptor(struct libusb_device *dev,
Expand All @@ -837,7 +838,7 @@ static int op_get_config_descriptor(struct libusb_device *dev,
config = &priv->config_descriptors[config_index];
len = MIN(len, config->actual_len);
memcpy(buffer, config->desc, len);
return len;
return (int)len;
}

/* send a control message to retrieve active configuration */
Expand Down Expand Up @@ -948,9 +949,11 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
} else if (wrapped_fd < 0) {
fd = get_usbfs_fd(dev, O_RDONLY, 0);
} else {
off_t offs;

fd = wrapped_fd;
r = lseek(fd, 0, SEEK_SET);
if (r < 0) {
offs = lseek(fd, 0, SEEK_SET);
if (offs < 0) {
usbi_err(ctx, "lseek failed, errno=%d", errno);
return LIBUSB_ERROR_IO;
}
Expand Down Expand Up @@ -1048,7 +1051,7 @@ static int linux_get_parent_info(struct libusb_device *dev, const char *sysfs_di

if ((tmp = strrchr(parent_sysfs_dir, '.')) ||
(tmp = strrchr(parent_sysfs_dir, '-'))) {
dev->port_number = atoi(tmp + 1);
dev->port_number = (uint8_t)atoi(tmp + 1);
*tmp = '\0';
} else {
usbi_warn(ctx, "Can not parse sysfs_dir: %s, no parent info",
Expand Down Expand Up @@ -1368,7 +1371,7 @@ static int op_wrap_sys_device(struct libusb_context *ctx,
/* There is no ioctl to get the bus number. We choose 0 here
* as linux starts numbering buses from 1. */
busnum = 0;
devaddr = ci.devnum;
devaddr = (uint8_t)ci.devnum;
}

/* Session id is unused as we do not add the device to the list of
Expand Down

0 comments on commit 6de7a80

Please sign in to comment.