Skip to content

Commit e96b3ed

Browse files
committed
Fix multiple warnings when building.
Fix #1: warning: format '%X' expects argument of type 'unsigned int', but argument 3 has type 'int32_t {aka long int}' [-Wformat=] The C++ specification requires "%X" to receive an unsigned value. Any other type (including signed values) is "undefined behavior". Fix #2: warning: narrowing conversion of '(((int)itfnum) + 1)' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing] The affected macros are returning a list of uint8_t values, typically to define statically-allocated byte arrays. The fix is to explicitly cast to `uint8_t` when doing arithmetic on any parameter. Also added explicit comment on the implied constraint.
1 parent 64b5555 commit e96b3ed

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
166166

167167
// CDC Descriptor Template
168168
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
169+
// NOTE: This returns an list of byte (uint_8) values
170+
// NOTE: Unwritten & unverified assumption: _itfnum is in range [0..254] (else overflows below adding 1)
169171
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
170172
/* Interface Associate */\
171173
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
@@ -174,15 +176,15 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
174176
/* CDC Header */\
175177
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
176178
/* CDC Call */\
177-
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (_itfnum) + 1,\
179+
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\
178180
/* CDC ACM: support line request */\
179181
4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
180182
/* CDC Union */\
181-
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (_itfnum) + 1,\
183+
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
182184
/* Endpoint Notification */\
183185
7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
184186
/* CDC Data Interface */\
185-
9, TUSB_DESC_INTERFACE, (_itfnum)+1, 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
187+
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
186188
/* Endpoint Out */\
187189
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
188190
/* Endpoint In */\
@@ -240,13 +242,15 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
240242
// MIDI simple descriptor
241243
// - 1 Embedded Jack In connected to 1 External Jack Out
242244
// - 1 Embedded Jack out connected to 1 External Jack In
245+
// NOTE: This returns an list of byte (uint_8) values
246+
// NOTE: Unwritten & unverified assumption: _itfnum is in range [0..254] (else overflows below adding 1)
243247
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
244248
/* Audio Control (AC) Interface */\
245249
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\
246250
/* AC Header */\
247-
9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, _itfnum+1,\
251+
9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, (uint8_t)((_itfnum)+1),\
248252
/* MIDI Streaming (MS) Interface */\
249-
9, TUSB_DESC_INTERFACE, _itfnum+1, 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\
253+
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\
250254
/* MS Header */\
251255
7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0025),\
252256
/* MS In Jack (Embedded) */\

cores/nRF5/utility/debug.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,13 @@ lookup_table_t const _strerr_table =
425425

426426
const char* dbg_err_str(int32_t err_id)
427427
{
428+
// TODO: verify it would be safe to change to int16_t
428429
const char * str = (const char *) lookup_find(&_strerr_table, err_id);
429430
static char unknown_str[7] = {0};
430431

431432
if ( str == NULL )
432433
{
433-
sprintf(unknown_str, "0x%04X", err_id);
434+
sprintf(unknown_str, "0x%04lX", (uint32_t)err_id);
434435
str = unknown_str;
435436
}
436437

0 commit comments

Comments
 (0)