@@ -54,6 +54,9 @@ int aggregate_status(struct buffer *aggregated_status, const struct buffer curre
5454
5555int aggregate_error (struct buffer *error_message, const struct buffer current_error_message, const struct buffer status,
5656 unsigned int device_type) {
57+ allocate (error_message, current_error_message.size_in_bytes );
58+ std::memcpy (error_message->data , current_error_message.data ,
59+ current_error_message.size_in_bytes );
5760 return OK;
5861}
5962
@@ -71,9 +74,13 @@ int status_data_valid(const struct buffer status, unsigned int device_type) {
7174 if (data == nullptr ) {
7275 return NOT_OK;
7376 }
77+ const std::string pressed_false = " {\" pressed\" : false}" ;
78+ const std::string pressed_true = " {\" pressed\" : true}" ;
79+
7480 switch (device_type) {
7581 case BUTTON_DEVICE_TYPE:
76- if (strncmp (data, " {\" pressed\" : false}" , status.size_in_bytes ) == 0 || strncmp (data, " {\" pressed\" : true}" , status.size_in_bytes ) == 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 )) {
7784 return OK;
7885 }
7986 break ;
@@ -89,9 +96,13 @@ int command_data_valid(const struct buffer command, unsigned int device_type) {
8996 if (data == nullptr ) {
9097 return NOT_OK;
9198 }
99+ const std::string lit_up_false = " {\" lit_up\" : false}" ;
100+ const std::string lit_up_true = " {\" lit_up\" : true}" ;
101+
92102 switch (device_type) {
93103 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 ) {
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 )) {
95106 return OK;
96107 }
97108 break ;
0 commit comments