diff --git a/src/Services/FunctionManagementService.cpp b/src/Services/FunctionManagementService.cpp index 7ad300f67637d39376546ed94658ef017d555945..8dcc602792b45199d17bf95e53330905ebcfaab0 100644 --- a/src/Services/FunctionManagementService.cpp +++ b/src/Services/FunctionManagementService.cpp @@ -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)); } diff --git a/test/Services/FunctionManagementService.cpp b/test/Services/FunctionManagementService.cpp index 5b2310b70c8c558b7c033e77a9b26938a69427e7..1cd99bf509a995fd08ce849965d0cd6d3f28a83c 100644 --- a/test/Services/FunctionManagementService.cpp +++ b/test/Services/FunctionManagementService.cpp @@ -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)); + } +}