Skip to content
Snippets Groups Projects
Commit 251b025e authored by Grigoris Pavlakis's avatar Grigoris Pavlakis Committed by kongr45gpen
Browse files

Fix bug in include() and update its test

parent ea253b39
No related branches found
No related tags found
No related merge requests found
......@@ -42,11 +42,11 @@ void FunctionManagementService::call(Message& msg) {
void FunctionManagementService::include(String<FUNC_NAME_LENGTH> funcName, void(*ptr)
(String<MAX_ARG_LENGTH>)) {
if (funcPtrIndex.full()) {
if (not funcPtrIndex.full()) { // CAUTION: etl::map won't check by itself if it's full
// before attempting to insert a key-value pair, causing segmentation faults. Check first!
funcName.append(FUNC_NAME_LENGTH - funcName.length(), '\0');
funcPtrIndex.insert(std::make_pair(funcName, ptr));
} else {
ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::FunctionMapFull);
return;
}
funcName.append(FUNC_NAME_LENGTH - funcName.length(), '\0');
funcPtrIndex.insert(std::make_pair(funcName, ptr));
}
......@@ -35,14 +35,18 @@ TEST_CASE("ST[08] - Call Tests") {
}
}
// WARNING! include() is malfunctioning - do not merge!
//TEST_CASE("ST[08] - Insert Tests") {
//
// SECTION("Insertion to full pointer map") {
// // make sure the pointer map is full to the brim
// ServiceTests::reset();
// std::string name = "test"; // FOR TESTING ONLY!
//
// }
//}
TEST_CASE("ST[08] - Insert Tests") {
SECTION("Insertion to full pointer map") {
// make sure the pointer map is full to the brim
ServiceTests::reset();
std::string name = "test"; // FOR TESTING ONLY!
for (int i = 0; i < FUNC_MAP_SIZE + 1; i++) {
name += std::to_string(i); // different names to fill up the map
fms.include(String<FUNC_NAME_LENGTH>(name.c_str()), &test);
}
CHECK(ServiceTests::thrownError(ErrorHandler::InternalErrorType::FunctionMapFull));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment