Device Status Bitmask Check Reverses Alerts Due to Operator Precedence
Level 2 · node · Correctness · Comparison precedence error in bit-flag checks
Scenario
A fictional equipment dashboard interprets integer status registers as bit flags. A maintenance indicator is present when mask 4 is set, and other flags may coexist in the same register. The current service combines a bitwise operation with an equality comparison without the required parentheses, so it can miss a real maintenance flag or display an alert for an unrelated flag.
Requirements
Change hasFlag so it returns true only when all bits specified by mask are present in flags. Other additional bits must not change the outcome, and a missing maintenance flag must return false. Preserve the device ID and maintenanceRequired fields in the status response.
Acceptance criteria
- A device with only the maintenance flag requires maintenance.
- A device with the maintenance flag and other flags still requires maintenance.
- A device with only an unrelated flag does not require maintenance.
- A device with zero status flags does not require maintenance.