Skip to content

Commit 50b36e7

Browse files
committed
fix status and command string comparisons
1 parent 493deda commit 50b36e7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

source/module_gateway/module_manager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ int status_data_valid(const struct buffer status, unsigned int device_type) {
7373
}
7474
switch(device_type) {
7575
case BUTTON_DEVICE_TYPE:
76-
if(strncmp(data, "{\"pressed\": false}", status.size_in_bytes) == 0 || strncmp(data, "{\"pressed\": true}", status.size_in_bytes) == 0) {
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) {
7778
return OK;
7879
}
7980
break;
@@ -91,7 +92,8 @@ int command_data_valid(const struct buffer command, unsigned int device_type) {
9192
}
9293
switch(device_type) {
9394
case BUTTON_DEVICE_TYPE:
94-
if(strncmp(data, "{\"lit_up\": false}", command.size_in_bytes) == 0 || strncmp(data, "{\"lit_up\": true}", command.size_in_bytes) == 0) {
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) {
9597
return OK;
9698
}
9799
break;

0 commit comments

Comments
 (0)