From 07abf4cbea566bf44c17e7cad09220ca301d1c73 Mon Sep 17 00:00:00 2001 From: Vadim Mikhailov Date: Tue, 21 Jan 2025 19:21:28 -0800 Subject: [PATCH] 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) --- Makefile | 2 +- uhubctl.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 1fd2c1b..4accf59 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ PKG_CONFIG ?= pkg-config CC ?= gcc CFLAGS ?= -g -O0 -CFLAGS += -Wall -Wextra -std=c99 -pedantic +CFLAGS += -Wall -Wextra -Wno-zero-length-array -std=c99 -pedantic GIT_VERSION := $(shell git describe --match "v[0-9]*" --abbrev=8 --dirty --tags | cut -c2-) ifeq ($(GIT_VERSION),) GIT_VERSION := $(shell cat VERSION) diff --git a/uhubctl.c b/uhubctl.c index 35df4f5..3a27284 100644 --- a/uhubctl.c +++ b/uhubctl.c @@ -405,7 +405,7 @@ static int get_computer_model(char *model, int len) * Returns 1 if yes and 0 otherwise. */ -static int check_computer_model(char *target) +static int check_computer_model(const char *target) { char model[256] = ""; 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) } /* Get container_id: */ - bzero(info->container_id, sizeof(info->container_id)); + memset(info->container_id, 0, sizeof(info->container_id)); struct libusb_bos_descriptor *bos; rc = libusb_get_bos_descriptor(devh, &bos); if (rc == 0) { @@ -743,7 +743,7 @@ static int get_device_description(struct libusb_device * dev, struct descriptor_ rc = libusb_get_device_descriptor(dev, &desc); if (rc) return rc; - bzero(ds, sizeof(*ds)); + memset(ds, 0, sizeof(*ds)); id_vendor = desc.idVendor; id_product = desc.idProduct; rc = libusb_open(dev, &devh); @@ -767,7 +767,7 @@ static int get_device_description(struct libusb_device * dev, struct descriptor_ } if (desc.bDeviceClass == LIBUSB_CLASS_HUB) { struct hub_info info; - bzero(&info, sizeof(info)); + memset(&info, 0, sizeof(info)); rc = get_hub_info(dev, &info); if (rc == 0) { const char * lpsm_type; @@ -825,7 +825,7 @@ static int print_port_status(struct hub_info * hub, int portmask) printf(" Port %d: %04x", port, port_status); struct descriptor_strings ds; - bzero(&ds, sizeof(ds)); + memset(&ds, 0, sizeof(ds)); struct libusb_device * udev; int i = 0; while ((udev = usb_devs[i++]) != NULL) { @@ -920,7 +920,7 @@ static int usb_find_hubs(void) if (rc == 0 && desc.bDeviceClass != LIBUSB_CLASS_HUB) continue; struct hub_info info; - bzero(&info, sizeof(info)); + memset(&info, 0, sizeof(info)); rc = get_hub_info(dev, &info); if (rc) { perm_ok = 0; /* USB permission issue? */ @@ -946,7 +946,7 @@ static int usb_find_hubs(void) (memcmp(info.port_numbers, dev_pn, info.pn_len) == 0)) { struct descriptor_strings ds; - bzero(&ds, sizeof(ds)); + memset(&ds, 0, sizeof(ds)); rc = get_device_description(udev, &ds); if (rc != 0) break;