Skip to content

Commit b49d949

Browse files
author
Cruz Monrreal
authored
Merge pull request #9393 from pan-/fix-safe-enum-type-safety
BLE: Fix SafeEnum type safety
2 parents 0bc9bcc + 79bd3ea commit b49d949

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

features/FEATURE_BLE/ble/SafeEnum.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,85 +112,87 @@ struct SafeEnum {
112112
*/
113113
typedef LayoutType representation_t;
114114

115+
protected:
115116
/**
116117
* Construction of an enumeration value.
117118
*/
118-
SafeEnum(LayoutType value) : _value(value) { }
119+
explicit SafeEnum(LayoutType value) : _value(value) { }
119120

121+
public:
120122
/**
121-
* Equal to operator for SafeEnum instances.
123+
* Equal to operator for Target instances.
122124
*
123125
* @param lhs left hand side of the comparison
124126
* @param rhs right hand side of the comparison
125127
*
126128
* @return true if the inner value of lhs and rhs are equal and false
127129
* otherwise.
128130
*/
129-
friend bool operator==(SafeEnum lhs, SafeEnum rhs) {
131+
friend bool operator==(Target lhs, Target rhs) {
130132
return lhs._value == rhs._value;
131133
}
132134

133135
/**
134-
* Not equal to operator for SafeEnum instances.
136+
* Not equal to operator for Target instances.
135137
*
136138
* @param lhs left hand side of the comparison
137139
* @param rhs right hand side of the comparison
138140
*
139141
* @return true if the inner value of lhs and rhs are not equal and false
140142
* otherwise.
141143
*/
142-
friend bool operator!=(SafeEnum lhs, SafeEnum rhs) {
144+
friend bool operator!=(Target lhs, Target rhs) {
143145
return !(lhs == rhs);
144146
}
145147

146148
/**
147-
* Less than operator for SafeEnum instances.
149+
* Less than operator for Target instances.
148150
*
149151
* @param lhs left hand side of the comparison
150152
* @param rhs right hand side of the comparison
151153
*
152154
* @return true if the inner value of lhs is less than rhs and false otherwise.
153155
*/
154-
friend bool operator<(SafeEnum lhs, SafeEnum rhs) {
156+
friend bool operator<(Target lhs, Target rhs) {
155157
return lhs.value() < rhs.value();
156158
}
157159

158160
/**
159-
* Less than or equal to operator for SafeEnum instances.
161+
* Less than or equal to operator for Target instances.
160162
*
161163
* @param lhs left hand side of the comparison
162164
* @param rhs right hand side of the comparison
163165
*
164166
* @return true if the inner value of lhs is less than or equal to rhs and
165167
* false otherwise.
166168
*/
167-
friend bool operator<=(SafeEnum lhs, SafeEnum rhs) {
169+
friend bool operator<=(Target lhs, Target rhs) {
168170
return lhs.value() < rhs.value() || lhs == rhs;
169171
}
170172

171173
/**
172-
* Greater than operator for SafeEnum instances.
174+
* Greater than operator for Target instances.
173175
*
174176
* @param lhs left hand side of the comparison
175177
* @param rhs right hand side of the comparison
176178
*
177179
* @return true if the inner value of lhs is greater than rhs; false
178180
* otherwise.
179181
*/
180-
friend bool operator>(SafeEnum lhs, SafeEnum rhs) {
182+
friend bool operator>(Target lhs, Target rhs) {
181183
return !(lhs <= rhs);
182184
}
183185

184186
/**
185-
* Greater than or equal to operator for SafeEnum instances.
187+
* Greater than or equal to operator for Target instances.
186188
*
187189
* @param lhs left hand side of the comparison
188190
* @param rhs right hand side of the comparison
189191
*
190192
* @return true if the inner value of lhs is greater than or equal to rhs;
191193
* false otherwise.
192194
*/
193-
friend bool operator>=(SafeEnum lhs, SafeEnum rhs) {
195+
friend bool operator>=(Target lhs, Target rhs) {
194196
return !(lhs < rhs);
195197
}
196198

features/FEATURE_BLE/source/gap/AdvertisingDataBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ uint8_t *AdvertisingDataBuilder::findField(adv_data_type_t type)
331331
for (uint8_t idx = 0; idx < _payload_length;) {
332332
uint8_t fieldType = _buffer[idx + FIELD_TYPE_INDEX];
333333

334-
if (fieldType == type) {
334+
if (fieldType == type.value()) {
335335
return _buffer.data() + idx;
336336
}
337337

0 commit comments

Comments
 (0)