Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple warnings when building. #322

Merged
merged 1 commit into from
Aug 17, 2019
Merged

Fix multiple warnings when building. #322

merged 1 commit into from
Aug 17, 2019

Conversation

henrygab
Copy link
Collaborator

Two types of warnings fixed.

First warnings:

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".

Second set of warnings:

warning: narrowing conversion of '(((int)itfnum) + 1)' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]

Affected macros were returning a list of uint8_t values, used to define statically-allocated byte arrays. Fixed by explicitly casting to uint8_t when doing arithmetic on any parameter. Notation also added to call out implied range constraint on the parameter _itfnum.

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.
Copy link
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for PR, these warning is really annoying 👍

@hathach hathach merged commit 080b524 into adafruit:master Aug 17, 2019
@henrygab henrygab deleted the Patch-BuildWarnings branch August 18, 2019 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants