Skip to content

BLE: Fix SafeEnum type safety #9393

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

Merged
merged 2 commits into from
Jan 28, 2019
Merged

Conversation

pan-
Copy link
Member

@pan- pan- commented Jan 16, 2019

Description

The relational operators were targeting the base class which defines an implicit constructor to an integral value. This is wrong as it allows SafeEnum instances to be compared against integers.

The fix is simple: define relationnal operators for the derived class. The derived class is known as it is passed as a template parameter of the base class.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@kjbracey-arm @paul-szczepanek-arm

@pan-
Copy link
Member Author

pan- commented Jan 16, 2019

Fix for one of the issue mentioned here

Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Seems fine - just editing. "Relationnal" misspelled in commit message.

@kjbracey
Copy link
Contributor

Actually, isn't it still a good idea to put an 'explicit' on the SafeEnum constructor, as I saw you did previously? Lack of it makes me worried what other path we might be missing - the safety failure came from the combination of that and the overload prototypes.

@pan- pan- force-pushed the fix-safe-enum-type-safety branch from 48dcd18 to 78c6ac7 Compare January 16, 2019 11:59
@pan-
Copy link
Member Author

pan- commented Jan 16, 2019

@kjbracey-arm Yes, that's a good idea to mark it as explicit. I don't recall why it wasn't (maybe just a mistake!) and tried it within our codebase and it doesn't yield any error. Going further I marked that constructor as protected as clients do not have any business in constructing SafeEnum outside a derived class.

@pan- pan- force-pushed the fix-safe-enum-type-safety branch from 78c6ac7 to f9393e0 Compare January 16, 2019 12:04
@0xc0170
Copy link
Contributor

0xc0170 commented Jan 16, 2019

Note: Travis failure is fixed on master (#9391) , if you can rebase to resolve the error

pan- added 2 commits January 16, 2019 16:06
The relationnal operators were targeting the base class which defines an implicit constructor to an integral value. This is wrong as it allows SafeEnum instances to be compared against integers.

The fix is simple: define relationnal operators for the derived class. The derived class is known as it is passed as a template parameter of the base class.

For extra safety the SafeEnum constructor is now explicit and protected.
@pan- pan- force-pushed the fix-safe-enum-type-safety branch from f9393e0 to 79bd3ea Compare January 16, 2019 16:06
@pan-
Copy link
Member Author

pan- commented Jan 16, 2019

@0xc0170 done.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 17, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jan 18, 2019

Test run: FAILED

Summary: 3 of 7 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@pan-
Copy link
Member Author

pan- commented Jan 25, 2019

@0xc0170 Examples fixed. Can we relaunch the CI ?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 28, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jan 28, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 2
Build artifacts

@cmonr cmonr merged commit b49d949 into ARMmbed:master Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants