make sure TOTAL_DRIVER_COUNT is not overflow 8-bit
This commit is contained in:
@@ -317,7 +317,7 @@ enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
|
|||||||
tu_static usbd_class_driver_t const * _app_driver = NULL;
|
tu_static usbd_class_driver_t const * _app_driver = NULL;
|
||||||
tu_static uint8_t _app_driver_count = 0;
|
tu_static uint8_t _app_driver_count = 0;
|
||||||
|
|
||||||
#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
|
#define TOTAL_DRIVER_COUNT ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
|
||||||
|
|
||||||
// virtually joins built-in and application drivers together.
|
// virtually joins built-in and application drivers together.
|
||||||
// Application is positioned first to allow overwriting built-in ones.
|
// Application is positioned first to allow overwriting built-in ones.
|
||||||
@@ -332,11 +332,9 @@ TU_ATTR_ALWAYS_INLINE static inline usbd_class_driver_t const * get_driver(uint8
|
|||||||
return driver;
|
return driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// DCD Event
|
// DCD Event
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
enum { RHPORT_INVALID = 0xFFu };
|
enum { RHPORT_INVALID = 0xFFu };
|
||||||
tu_static uint8_t _usbd_rhport = RHPORT_INVALID;
|
tu_static uint8_t _usbd_rhport = RHPORT_INVALID;
|
||||||
|
|
||||||
@@ -488,6 +486,7 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
|
|||||||
// Get application driver if available
|
// Get application driver if available
|
||||||
if (usbd_app_driver_get_cb) {
|
if (usbd_app_driver_get_cb) {
|
||||||
_app_driver = usbd_app_driver_get_cb(&_app_driver_count);
|
_app_driver = usbd_app_driver_get_cb(&_app_driver_count);
|
||||||
|
TU_ASSERT(_app_driver_count + BUILTIN_DRIVER_COUNT <= UINT8_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init class drivers
|
// Init class drivers
|
||||||
|
Reference in New Issue
Block a user