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

BLE: Fix SafeEnum type safety #9393

Merged
merged 2 commits into from Jan 28, 2019

Conversation

Projects
None yet
6 participants
@pan-
Copy link
Member

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-

This comment has been minimized.

Copy link
Member Author

pan- commented Jan 16, 2019

Fix for one of the issue mentioned here

@kjbracey-arm
Copy link
Contributor

kjbracey-arm left a comment

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

Show resolved Hide resolved features/FEATURE_BLE/ble/SafeEnum.h
@kjbracey-arm

This comment has been minimized.

Copy link
Contributor

kjbracey-arm commented Jan 16, 2019

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 pan-:fix-safe-enum-type-safety branch Jan 16, 2019

@pan-

This comment has been minimized.

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 pan-:fix-safe-enum-type-safety branch Jan 16, 2019

@0xc0170

This comment has been minimized.

Copy link
Member

0xc0170 commented Jan 16, 2019

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

pan- added some commits Jan 16, 2019

BLE: Fix relationnal operator of SafeEnum
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 pan-:fix-safe-enum-type-safety branch to 79bd3ea Jan 16, 2019

@pan-

This comment has been minimized.

Copy link
Member Author

pan- commented Jan 16, 2019

@0xc0170 done.

@0xc0170

This comment has been minimized.

Copy link
Member

0xc0170 commented Jan 17, 2019

CI started

@mbed-ci

This comment has been minimized.

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-

This comment has been minimized.

Copy link
Member Author

pan- commented Jan 25, 2019

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

@0xc0170

This comment has been minimized.

Copy link
Member

0xc0170 commented Jan 28, 2019

CI started

@mbed-ci

This comment has been minimized.

Copy link

mbed-ci commented Jan 28, 2019

Test run: SUCCESS

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

@0xc0170 0xc0170 added ready for merge and removed needs: CI labels Jan 28, 2019

@cmonr cmonr merged commit b49d949 into ARMmbed:master Jan 28, 2019

23 checks passed

continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci/build-ARM Success
Details
jenkins-ci/build-ARMC6 Success
Details
jenkins-ci/build-GCC_ARM Success
Details
jenkins-ci/build-IAR Success
Details
jenkins-ci/cloud-client-test Success
Details
jenkins-ci/dynamic-memory-usage RTOS ROM(+0 bytes) RAM(+0 bytes)
Details
jenkins-ci/exporter Success
Details
jenkins-ci/greentea-test Success
Details
jenkins-ci/mbed2-build-ARM Success
Details
jenkins-ci/mbed2-build-GCC_ARM Success
Details
jenkins-ci/mbed2-build-IAR Success
Details
jenkins-ci/unittests Success
Details
travis-ci/astyle Local astyle testing has passed
Details
travis-ci/docs Local docs testing has passed
Details
travis-ci/doxy-spellcheck Local doxy-spellcheck testing has passed
Details
travis-ci/events Passed, runtime is 10387 cycles (+7 cycles)
Details
travis-ci/gitattributestest Local gitattributestest testing has passed
Details
travis-ci/licence_check Local licence_check testing has passed
Details
travis-ci/littlefs Passed, code size is 8372B (+0.00%)
Details
travis-ci/psa-autogen Local psa-autogen testing has passed
Details
travis-ci/tools-py2.7 Local tools-py2.7 testing has passed
Details

@cmonr cmonr removed the ready for merge label Jan 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.