Skip to content

Commit 07abf4c

Browse files
committed
Fix warnings when compiled in C++ mode
Fixed all warnings when compiling with `c++ -std=c++11 ...`: * bzero() appears to be deprecated, replaced with memset() * fixed few const warnings * suppressed zero array warnings (emitted by libusb headers)
1 parent d483981 commit 07abf4c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PKG_CONFIG ?= pkg-config
1414

1515
CC ?= gcc
1616
CFLAGS ?= -g -O0
17-
CFLAGS += -Wall -Wextra -std=c99 -pedantic
17+
CFLAGS += -Wall -Wextra -Wno-zero-length-array -std=c99 -pedantic
1818
GIT_VERSION := $(shell git describe --match "v[0-9]*" --abbrev=8 --dirty --tags | cut -c2-)
1919
ifeq ($(GIT_VERSION),)
2020
GIT_VERSION := $(shell cat VERSION)

uhubctl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static int get_computer_model(char *model, int len)
405405
* Returns 1 if yes and 0 otherwise.
406406
*/
407407

408-
static int check_computer_model(char *target)
408+
static int check_computer_model(const char *target)
409409
{
410410
char model[256] = "";
411411
if (get_computer_model(model, sizeof(model)) == 0) {
@@ -495,7 +495,7 @@ static int get_hub_info(struct libusb_device *dev, struct hub_info *info)
495495
}
496496

497497
/* Get container_id: */
498-
bzero(info->container_id, sizeof(info->container_id));
498+
memset(info->container_id, 0, sizeof(info->container_id));
499499
struct libusb_bos_descriptor *bos;
500500
rc = libusb_get_bos_descriptor(devh, &bos);
501501
if (rc == 0) {
@@ -743,7 +743,7 @@ static int get_device_description(struct libusb_device * dev, struct descriptor_
743743
rc = libusb_get_device_descriptor(dev, &desc);
744744
if (rc)
745745
return rc;
746-
bzero(ds, sizeof(*ds));
746+
memset(ds, 0, sizeof(*ds));
747747
id_vendor = desc.idVendor;
748748
id_product = desc.idProduct;
749749
rc = libusb_open(dev, &devh);
@@ -767,7 +767,7 @@ static int get_device_description(struct libusb_device * dev, struct descriptor_
767767
}
768768
if (desc.bDeviceClass == LIBUSB_CLASS_HUB) {
769769
struct hub_info info;
770-
bzero(&info, sizeof(info));
770+
memset(&info, 0, sizeof(info));
771771
rc = get_hub_info(dev, &info);
772772
if (rc == 0) {
773773
const char * lpsm_type;
@@ -825,7 +825,7 @@ static int print_port_status(struct hub_info * hub, int portmask)
825825
printf(" Port %d: %04x", port, port_status);
826826

827827
struct descriptor_strings ds;
828-
bzero(&ds, sizeof(ds));
828+
memset(&ds, 0, sizeof(ds));
829829
struct libusb_device * udev;
830830
int i = 0;
831831
while ((udev = usb_devs[i++]) != NULL) {
@@ -920,7 +920,7 @@ static int usb_find_hubs(void)
920920
if (rc == 0 && desc.bDeviceClass != LIBUSB_CLASS_HUB)
921921
continue;
922922
struct hub_info info;
923-
bzero(&info, sizeof(info));
923+
memset(&info, 0, sizeof(info));
924924
rc = get_hub_info(dev, &info);
925925
if (rc) {
926926
perm_ok = 0; /* USB permission issue? */
@@ -946,7 +946,7 @@ static int usb_find_hubs(void)
946946
(memcmp(info.port_numbers, dev_pn, info.pn_len) == 0))
947947
{
948948
struct descriptor_strings ds;
949-
bzero(&ds, sizeof(ds));
949+
memset(&ds, 0, sizeof(ds));
950950
rc = get_device_description(udev, &ds);
951951
if (rc != 0)
952952
break;

0 commit comments

Comments
 (0)