summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-03-30 12:38:47 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2020-03-30 12:38:47 -0700
commit95bbfb6023877ca25720f04203ef2aa2f691e995 (patch)
tree66fab38659c1b0a9cbc3d4ae85b6f5cf3ce79c44
parent9a1bc8cafb904c20a869c74ad6d657686a1c4bb1 (diff)
downloadlibusb-95bbfb6023877ca25720f04203ef2aa2f691e995.tar.gz
build: Enable additional build errors and warnings
Help catch more errors by enabling additional build errors and warnings. Address some of the warnings seen with these new flags, including moving the libusb_transfer structure back out of the usbi_transfer structure to address 'warning: invalid use of structure with flexible array member'. Apparently a structure ending with a flexible array member is not okay with the compiler as the last member within another structure. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--.travis.yml4
-rw-r--r--configure.ac17
-rw-r--r--examples/sam3u_benchmark.c2
-rw-r--r--examples/xusb.c3
-rw-r--r--libusb/io.c1
-rw-r--r--libusb/libusbi.h14
-rw-r--r--libusb/os/linux_udev.c6
-rw-r--r--libusb/os/poll_windows.c4
-rw-r--r--libusb/os/windows_common.c5
-rw-r--r--libusb/os/windows_winusb.c43
-rw-r--r--libusb/version_nano.h2
-rwxr-xr-xtravis-autogen.sh21
12 files changed, 79 insertions, 43 deletions
diff --git a/.travis.yml b/.travis.yml
index eb477a1..0111925 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -48,6 +48,6 @@ addons:
- ubuntu-toolchain-r-test
script:
- - ./autogen.sh && make clean && make
- - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./travis-autogen.sh --disable-udev && make clean && make ; fi
+ - ./travis-autogen.sh && make -j4
+ - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && ./travis-autogen.sh --disable-udev && make -j4 ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cd Xcode && xcodebuild -project libusb.xcodeproj ; fi
diff --git a/configure.ac b/configure.ac
index 2d6cfad..32f4244 100644
--- a/configure.ac
+++ b/configure.ac
@@ -318,10 +318,23 @@ AM_CONDITIONAL([THREADS_POSIX], [test "x$threads" = xposix])
AM_CONDITIONAL([THREADS_WINDOWS], [test "x$threads" = xwindows])
AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
-AM_CFLAGS="${AM_CFLAGS} -Wall -Wshadow -Wstrict-prototypes -Wundef -Wunused -Werror=implicit-function-declaration"
+EXTRA_CFLAGS=
+
+dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
+dnl Windows with GCC 8 or later because of dynamically loaded functions
+if test "x$backend" = xwindows; then
+ saved_CFLAGS="${CFLAGS}"
+ CFLAGS="-Werror -Wcast-function-type"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
+ [EXTRA_CFLAGS="-Wno-cast-function-type"],
+ [])
+ CFLAGS="${saved_CFLAGS}"
+fi
+
+AM_CFLAGS="${AM_CFLAGS} -Wall -Wextra -Wshadow -Wunused -Wwrite-strings -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=init-self -Werror=missing-prototypes -Werror=strict-prototypes -Werror=undef -Werror=uninitialized ${EXTRA_CFLAGS}"
AC_SUBST(AM_CFLAGS)
-AM_CXXFLAGS="${AM_CFLAGS}"
+AM_CXXFLAGS="${AM_CFLAGS} -Wmissing-declarations"
AC_SUBST(AM_CXXFLAGS)
AC_SUBST(LT_LDFLAGS)
diff --git a/examples/sam3u_benchmark.c b/examples/sam3u_benchmark.c
index 43d286a..68c2d50 100644
--- a/examples/sam3u_benchmark.c
+++ b/examples/sam3u_benchmark.c
@@ -146,7 +146,7 @@ static void sig_hdlr(int signum)
}
}
-int main(int argc, char **argv)
+int main(void)
{
int rc;
struct sigaction sigact;
diff --git a/examples/xusb.c b/examples/xusb.c
index 46fb750..bf328fe 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -971,6 +971,7 @@ static int test_device(uint16_t vid, uint16_t pid)
int main(int argc, char** argv)
{
+ static char debug_env_str[] = "LIBUSB_DEBUG=4"; // LIBUSB_LOG_LEVEL_DEBUG
bool show_help = false;
bool debug_mode = false;
const struct libusb_version* version;
@@ -1098,7 +1099,7 @@ int main(int argc, char** argv)
// but since we can't call on libusb_set_option() before libusb_init(), we use the env variable method
old_dbg_str = getenv("LIBUSB_DEBUG");
if (debug_mode) {
- if (putenv("LIBUSB_DEBUG=4") != 0) // LIBUSB_LOG_LEVEL_DEBUG
+ if (putenv(debug_env_str) != 0)
printf("Unable to set debug level\n");
}
diff --git a/libusb/io.c b/libusb/io.c
index 5457d0e..907d28e 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -1267,6 +1267,7 @@ struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(
priv_size = PTR_ALIGN(usbi_backend.transfer_priv_size);
alloc_size = priv_size
+ sizeof(struct usbi_transfer)
+ + sizeof(struct libusb_transfer)
+ (sizeof(struct libusb_iso_packet_descriptor) * (size_t)iso_packets);
ptr = calloc(1, alloc_size);
if (!ptr)
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 9eeb920..2fa4e11 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -503,8 +503,6 @@ struct usbi_transfer {
usbi_mutex_t lock;
void *priv;
-
- struct libusb_transfer libusb_transfer;
};
enum usbi_transfer_state_flags {
@@ -529,10 +527,14 @@ enum usbi_transfer_timeout_flags {
USBI_TRANSFER_TIMED_OUT = 1U << 2,
};
-#define USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer) \
- (&(itransfer)->libusb_transfer)
-#define LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
- container_of(transfer, struct usbi_transfer, libusb_transfer)
+#define USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer) \
+ ((struct libusb_transfer *) \
+ ((unsigned char *)(itransfer) \
+ + PTR_ALIGN(sizeof(struct usbi_transfer))))
+#define LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
+ ((struct usbi_transfer *) \
+ ((unsigned char *)(transfer) \
+ - PTR_ALIGN(sizeof(struct usbi_transfer))))
/* All standard descriptors have these 2 fields in common */
struct usb_descriptor_header {
diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c
index d8851cf..33a9174 100644
--- a/libusb/os/linux_udev.c
+++ b/libusb/os/linux_udev.c
@@ -131,7 +131,7 @@ err:
int linux_udev_stop_event_monitor(void)
{
char dummy = 1;
- int r;
+ ssize_t r;
assert(udev_ctx != NULL);
assert(udev_monitor != NULL);
@@ -176,13 +176,15 @@ static void *linux_udev_event_thread_main(void *arg)
.events = POLLIN},
};
+ UNUSED(arg);
+
#if defined(HAVE_PTHREAD_SETNAME_NP)
r = pthread_setname_np(pthread_self(), "libusb_event");
if (r)
usbi_warn(NULL, "failed to set hotplug event thread name, error=%d", r);
#endif
- usbi_dbg("udev event thread entering.");
+ usbi_dbg("udev event thread entering");
while ((r = poll(fds, 2, -1)) >= 0 || errno == EINTR) {
if (r < 0) {
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c
index 490ee7f..5497088 100644
--- a/libusb/os/poll_windows.c
+++ b/libusb/os/poll_windows.c
@@ -222,7 +222,7 @@ static DWORD WINAPI WaitThread(LPVOID lpParam)
DWORD status;
status = WaitForMultipleObjects(thread_data->num_handles, thread_data->handles, FALSE, INFINITE);
- if ((status >= WAIT_OBJECT_0) && (status < (WAIT_OBJECT_0 + thread_data->num_handles))) {
+ if (status < (WAIT_OBJECT_0 + thread_data->num_handles)) {
if (status > WAIT_OBJECT_0) {
// This will wake up all the other waiting threads
SetEvent(notify_event);
@@ -291,7 +291,7 @@ static DWORD poll_wait(const HANDLE *wait_handles, DWORD num_wait_handles, DWORD
}
status = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, handles, FALSE, timeout);
- if ((status >= WAIT_OBJECT_0) && (status < (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS))) {
+ if (status < (WAIT_OBJECT_0 + MAXIMUM_WAIT_OBJECTS)) {
if (status > WAIT_OBJECT_0) {
// Wake up all the waiting threads
SetEvent(notify_event);
diff --git a/libusb/os/windows_common.c b/libusb/os/windows_common.c
index debff74..418b6b7 100644
--- a/libusb/os/windows_common.c
+++ b/libusb/os/windows_common.c
@@ -565,7 +565,7 @@ static int windows_set_option(struct libusb_context *ctx, enum libusb_option opt
UNUSED(ap);
- switch (option) {
+ switch ((int)option) {
case LIBUSB_OPTION_USE_USBDK:
if (usbdk_available) {
usbi_dbg("switching context %p to use UsbDk backend", ctx);
@@ -832,7 +832,8 @@ int usbi_clock_gettime(int clk_id, struct timespec *tp)
tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency) * hires_ticks_to_ps) / UINT64_C(1000));
return 0;
}
- // Fall through and return real-time if monotonic was not detected @ timer init
+ // Return real-time if monotonic was not detected @ timer init
+ // Fall through
case USBI_CLOCK_REALTIME:
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
if (!timespec_get(tp, TIME_UTC)) {
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index 245df90..67013d6 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -1137,7 +1137,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_
unsigned int guid_size = GUID_SIZE_STEP;
unsigned int nb_guids;
// Keep a list of PnP enumerator strings that are found
- char *usb_enumerator[8] = { "USB" };
+ const char *usb_enumerator[8] = { "USB" };
unsigned int nb_usb_enumerators = 1;
unsigned int usb_enum_index = 0;
// Keep a list of newly allocated devs to unref
@@ -1518,7 +1518,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_
// Free any PnP enumerator strings
for (i = 1; i < nb_usb_enumerators; i++)
- free(usb_enumerator[i]);
+ free((void *)usb_enumerator[i]);
// Unref newly allocated devs
for (i = 0; i < unref_cur; i++)
@@ -1835,12 +1835,44 @@ const struct windows_usb_api_backend usb_api_backend[USB_API_MAX] = {
{
USB_API_UNSUPPORTED,
"Unsupported API",
- // No supported operations
+ NULL, /* driver_name_list */
+ 0, /* nb_driver_names */
+ NULL, /* init */
+ NULL, /* exit */
+ NULL, /* open */
+ NULL, /* close */
+ NULL, /* configure_endpoints */
+ NULL, /* claim_interface */
+ NULL, /* set_interface_altsetting */
+ NULL, /* release_interface */
+ NULL, /* clear_halt */
+ NULL, /* reset_device */
+ NULL, /* submit_bulk_transfer */
+ NULL, /* submit_iso_transfer */
+ NULL, /* submit_control_transfer */
+ NULL, /* cancel_transfer */
+ NULL, /* copy_transfer_data */
},
{
USB_API_HUB,
"HUB API",
- // No supported operations
+ NULL, /* driver_name_list */
+ 0, /* nb_driver_names */
+ NULL, /* init */
+ NULL, /* exit */
+ NULL, /* open */
+ NULL, /* close */
+ NULL, /* configure_endpoints */
+ NULL, /* claim_interface */
+ NULL, /* set_interface_altsetting */
+ NULL, /* release_interface */
+ NULL, /* clear_halt */
+ NULL, /* reset_device */
+ NULL, /* submit_bulk_transfer */
+ NULL, /* submit_iso_transfer */
+ NULL, /* submit_control_transfer */
+ NULL, /* cancel_transfer */
+ NULL, /* copy_transfer_data */
},
{
USB_API_COMPOSITE,
@@ -3990,7 +4022,8 @@ static int composite_submit_control_transfer(int sub_api, struct usbi_transfer *
libusb_free_config_descriptor(conf_desc);
break;
}
- // Fall through if not able to determine interface
+ // No break if not able to determine interface
+ // Fall through
default:
iface = -1;
break;
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 5708a99..1958a1e 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11479
+#define LIBUSB_NANO 11480
diff --git a/travis-autogen.sh b/travis-autogen.sh
index cdd8781..7acf941 100755
--- a/travis-autogen.sh
+++ b/travis-autogen.sh
@@ -1,39 +1,22 @@
#!/bin/bash
-# Warnings enabled
-CFLAGS="-Wall -Wextra"
+CFLAGS="-O2"
CFLAGS+=" -Wbad-function-cast"
#CFLAGS+=" -Wcast-align"
-CFLAGS+=" -Wchar-subscripts"
-CFLAGS+=" -Wempty-body"
-CFLAGS+=" -Wformat"
CFLAGS+=" -Wformat-security"
CFLAGS+=" -Winit-self"
CFLAGS+=" -Winline"
-CFLAGS+=" -Wmissing-declarations"
CFLAGS+=" -Wmissing-include-dirs"
-CFLAGS+=" -Wmissing-prototypes"
CFLAGS+=" -Wnested-externs"
CFLAGS+=" -Wold-style-definition"
CFLAGS+=" -Wpointer-arith"
CFLAGS+=" -Wredundant-decls"
-CFLAGS+=" -Wshadow"
-CFLAGS+=" -Wstrict-prototypes"
CFLAGS+=" -Wswitch-enum"
-CFLAGS+=" -Wundef"
-CFLAGS+=" -Wuninitialized"
-CFLAGS+=" -Wunused"
-CFLAGS+=" -Wwrite-strings"
# warnings disabled on purpose
-CFLAGS+=" -Wno-unused-parameter"
-CFLAGS+=" -Wno-unused-function"
CFLAGS+=" -Wno-deprecated-declarations"
-# should be removed and the code fixed
-CFLAGS+=" -Wno-incompatible-pointer-types-discards-qualifiers"
-
export CFLAGS
-./autogen.sh "$@"
+exec ./autogen.sh "$@"