Skip to content

Commit 237fdca

Browse files
committed
return default error if input is nullptr
1 parent 8c42eaf commit 237fdca

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

include/common/example_module.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
22

33
static constexpr unsigned int BUTTON_DEVICE_TYPE{0};
4-
static constexpr unsigned int MODULE_NUMBER{1000};
4+
static constexpr unsigned int MODULE_NUMBER{1000};
5+
static constexpr char DEFAULT_ERROR_MESSAGE[]{"Default error"};

source/module_gateway/module_manager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ int aggregate_status(struct buffer *aggregated_status, const struct buffer curre
5454

5555
int 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 );
57+
if (current_error_message.data != nullptr) {
58+
allocate(error_message, current_error_message.size_in_bytes);
59+
std::memcpy(error_message->data, current_error_message.data,
60+
current_error_message.size_in_bytes);
61+
} else {
62+
const std::string current_error_message_str = DEFAULT_ERROR_MESSAGE;
63+
allocate(error_message, current_error_message_str.size());
64+
std::memcpy(error_message->data, current_error_message_str.c_str(),
65+
current_error_message_str.size());
66+
}
6067
return OK;
6168
}
6269

0 commit comments

Comments
 (0)