@@ -74,13 +74,13 @@ int status_data_valid(const struct buffer status, unsigned int device_type) {
7474 if (data == nullptr ) {
7575 return NOT_OK;
7676 }
77- std::string pressed_false = " {\" pressed\" : false}" ;
78- std::string pressed_true = " {\" pressed\" : true}" ;
77+ const std::string pressed_false = " {\" pressed\" : false}" ;
78+ const std::string pressed_true = " {\" pressed\" : true}" ;
7979
8080 switch (device_type) {
8181 case BUTTON_DEVICE_TYPE:
82- if ( strncmp (pressed_false.c_str (), data, std::max ( status.size_in_bytes , pressed_false. size ())) == 0 ||
83- strncmp (pressed_true.c_str (), data, std::max ( status.size_in_bytes , pressed_true. size ())) == 0 ) {
82+ if ((status. size_in_bytes == pressed_false. size () && strncmp (pressed_false.c_str (), data, status.size_in_bytes ) == 0 ) ||
83+ (status. size_in_bytes == pressed_true. size () && strncmp (pressed_true.c_str (), data, status.size_in_bytes ) == 0 ) ) {
8484 return OK;
8585 }
8686 break ;
@@ -96,13 +96,13 @@ int command_data_valid(const struct buffer command, unsigned int device_type) {
9696 if (data == nullptr ) {
9797 return NOT_OK;
9898 }
99- std::string lit_up_false = " {\" lit_up\" : false}" ;
100- std::string lit_up_true = " {\" lit_up\" : true}" ;
99+ const std::string lit_up_false = " {\" lit_up\" : false}" ;
100+ const std::string lit_up_true = " {\" lit_up\" : true}" ;
101101
102102 switch (device_type) {
103103 case BUTTON_DEVICE_TYPE:
104- if ( strncmp (lit_up_false.c_str (), data, std::max ( command.size_in_bytes , lit_up_false. size ())) == 0 ||
105- strncmp (lit_up_true.c_str (), data, std::max ( command.size_in_bytes , lit_up_true. size ())) == 0 ) {
104+ if ((command. size_in_bytes == lit_up_false. size () && strncmp (lit_up_false.c_str (), data, command.size_in_bytes ) == 0 ) ||
105+ (command. size_in_bytes == lit_up_true. size () && strncmp (lit_up_true.c_str (), data, command.size_in_bytes ) == 0 ) ) {
106106 return OK;
107107 }
108108 break ;
0 commit comments