summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-04-16 15:57:15 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2020-04-16 15:57:15 -0700
commite83f39ba6e0368d8b253a5f0b02bfd115763e0b4 (patch)
tree167cc527b1bef03b777fe3b6a14aec68d75d0578
parent61c457a699d211848efcbe538d949768e01b1d32 (diff)
downloadlibusb-e83f39ba6e0368d8b253a5f0b02bfd115763e0b4.tar.gz
libusb.h: Ensure that struct libusb_control_transfer is not padded
There is nothing explicitly preventing the compiler from adding any sort of padding to the libusb_control_transfer structure. It does not seem that any sane compiler would do so, but there is library functionality that depends on this not happening. Address this by explicitly instructing the compiler to pack the structure. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--doc/doxygen.cfg.in3
-rw-r--r--libusb/libusb.h14
-rw-r--r--libusb/version_nano.h2
3 files changed, 16 insertions, 3 deletions
diff --git a/doc/doxygen.cfg.in b/doc/doxygen.cfg.in
index 504d41c..f4ccf1e 100644
--- a/doc/doxygen.cfg.in
+++ b/doc/doxygen.cfg.in
@@ -2113,7 +2113,8 @@ INCLUDE_FILE_PATTERNS =
PREDEFINED = API_EXPORTED= \
DEFAULT_VISIBILITY= \
- LIBUSB_CALL=
+ LIBUSB_CALL= \
+ LIBUSB_PACKED=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 058569e..360f654 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -72,6 +72,12 @@ typedef SSIZE_T ssize_t;
#define LIBUSB_DEPRECATED_FOR(f)
#endif /* __GNUC__ */
+#if defined(__GNUC__)
+#define LIBUSB_PACKED __attribute__ ((packed))
+#else
+#define LIBUSB_PACKED
+#endif /* __GNUC__ */
+
/** \def LIBUSB_CALL
* \ingroup libusb_misc
* libusb's Windows calling convention.
@@ -895,6 +901,9 @@ struct libusb_container_id_descriptor {
/** \ingroup libusb_asyncio
* Setup packet for control transfers. */
+#if defined(_MSC_VER)
+#pragma pack(push, 1)
+#endif
struct libusb_control_setup {
/** Request type. Bits 0:4 determine recipient, see
* \ref libusb_request_recipient. Bits 5:6 determine type, see
@@ -919,7 +928,10 @@ struct libusb_control_setup {
/** Number of bytes to transfer */
uint16_t wLength;
-};
+} LIBUSB_PACKED;
+#if defined(_MSC_VER)
+#pragma pack(pop)
+#endif
#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 0e6fc9c..459f6be 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11496
+#define LIBUSB_NANO 11497