Skip to content

Commit 02308d4

Browse files
committed
dont use magic numbers
1 parent 3d3906c commit 02308d4

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

source/module_gateway/module_manager.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ int status_data_valid(const struct buffer status, unsigned int device_type) {
7171
if(data == nullptr) {
7272
return NOT_OK;
7373
}
74+
std::string pressed_false = "{\"pressed\": false}";
75+
std::string pressed_true = "{\"pressed\": true}";
76+
7477
switch(device_type) {
7578
case BUTTON_DEVICE_TYPE:
76-
if(strncmp("{\"pressed\": false}", data, std::max(status.size_in_bytes, std::size_t(19))) == 0 ||
77-
strncmp("{\"pressed\": true}", data, std::max(status.size_in_bytes, std::size_t(18))) == 0) {
79+
if(strncmp(pressed_false.c_str(), data, std::max(status.size_in_bytes, pressed_false.size())) == 0 ||
80+
strncmp(pressed_true.c_str(), data, std::max(status.size_in_bytes, pressed_true.size())) == 0) {
7881
return OK;
7982
}
8083
break;
@@ -90,10 +93,13 @@ int command_data_valid(const struct buffer command, unsigned int device_type) {
9093
if(data == nullptr) {
9194
return NOT_OK;
9295
}
96+
std::string lit_up_false = "{\"lit_up\": false}";
97+
std::string lit_up_true = "{\"lit_up\": true}";
98+
9399
switch(device_type) {
94100
case BUTTON_DEVICE_TYPE:
95-
if(strncmp("{\"lit_up\": false}", data, std::max(command.size_in_bytes, std::size_t(18))) == 0 ||
96-
strncmp("{\"lit_up\": true}", data, std::max(command.size_in_bytes, std::size_t(17))) == 0) {
101+
if(strncmp(lit_up_false.c_str(), data, std::max(command.size_in_bytes, lit_up_false.size())) == 0 ||
102+
strncmp(lit_up_true.c_str(), data, std::max(command.size_in_bytes, lit_up_true.size())) == 0) {
97103
return OK;
98104
}
99105
break;

0 commit comments

Comments
 (0)