bitwise and operator used on sequential enum values #301
Labels
topic: code
Related to content of the project itself
type: imperfection
Perceived defect in any part of project
Throughout WiFi.cpp, the _status variable is tested using the bitwise and operator, but its possible values are not bitmasks. This looks wrong.
For example, at line 450 we have
if (!(_status & WL_CONNECTED)) {
The value of WL_CONNECTED is 3, so the expression (_status & WL_CONNECTED) is true if either of the lowest order 2 bits is set in _status. That makes line 450 behave the same as:
if (!(_status == WL_NO_SSID_AVAIL || _status == WL_SCAN_COMPLETED || _status == WL_CONNECTED || _status == WL_CONNECTION_LOST || _status == WL_DISCONNECTED || _status == WL_AP_LISTENING || _status == WL_AP_FAILED || _status == WL_PROVISIONING || _status == WL_PROVISIONING_FAILED)) {
And since line 446 looks like it intended to break out of the loop when _status was either WL_CONNECTED or WL_DISCONNECTED (but not quite because the same bug exists there), then line 450's if statement never succeeds because it doesn't distinguish between those two values. I believe the intended behavior of line 450 is instead
if (!(status_ == WL_CONNECTED)) {
or the simpler
if (status != WL_CONNECTED) {
The text was updated successfully, but these errors were encountered: