Skip to content

Commit

Permalink
Fix unit test failing on ubuntu 24.04LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jan 31, 2025
1 parent 3d58fdd commit 57de417
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 4 additions & 14 deletions engine/core/src/routing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,18 @@ static void RoutingTB_AddNumToAlias(char *alias, uint8_t num)
uint8_t intsize = 1;
if (num > 9)
{
// The string size of num is 2
// The string size of num have a size of 2
intsize = 2;
}
if (num > 99) // only 2 digit are alowed when add alias number
{
// This is probably a mistake, put an error into the alias
memset(alias, 0, MAX_ALIAS_SIZE - 1);
memcpy(alias, "error", strlen("error"));
return;
}
LUOS_ASSERT(num < 100); // only 2 digit are alowed when add alias number
// Change size to fit into 15 characters
if (strlen(alias) > (MAX_ALIAS_SIZE - 1 - intsize))
{
alias[(MAX_ALIAS_SIZE - 1 - intsize)] = '\0';
}
else
{
alias[strlen(alias)] = '\0';
}
// Add a number at the end of the alias
char *alias_copy = alias;
sprintf(alias, "%s%d", alias_copy, num);
char *end_pointer = &alias[strlen(alias)];
sprintf(end_pointer, "%d", num);
}

/******************************************************************************
Expand Down
14 changes: 14 additions & 0 deletions test/tests_core/test_routing_table/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ void unittest_RoutingTB_AddNumToAlias(void)
}
TEST_ASSERT_TRUE(IS_ASSERT());
END_TRY;
TRY
{
char alias[MAX_ALIAS_SIZE] = "Dummy_App";
RoutingTB_AddNumToAlias(alias, 100);
}
TEST_ASSERT_TRUE(IS_ASSERT());
END_TRY;
TRY
{
char alias[MAX_ALIAS_SIZE] = "Dummy_App";
RoutingTB_AddNumToAlias(alias, 101);
}
TEST_ASSERT_TRUE(IS_ASSERT());
END_TRY;
}

NEW_TEST_CASE("check RoutingTB_AddNumToAlias return value");
Expand Down

0 comments on commit 57de417

Please sign in to comment.