Skip to content

Commit 57de417

Browse files
Fix unit test failing on ubuntu 24.04LTS
1 parent 3d58fdd commit 57de417

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

engine/core/src/routing_table.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,18 @@ static void RoutingTB_AddNumToAlias(char *alias, uint8_t num)
185185
uint8_t intsize = 1;
186186
if (num > 9)
187187
{
188-
// The string size of num is 2
188+
// The string size of num have a size of 2
189189
intsize = 2;
190190
}
191-
if (num > 99) // only 2 digit are alowed when add alias number
192-
{
193-
// This is probably a mistake, put an error into the alias
194-
memset(alias, 0, MAX_ALIAS_SIZE - 1);
195-
memcpy(alias, "error", strlen("error"));
196-
return;
197-
}
191+
LUOS_ASSERT(num < 100); // only 2 digit are alowed when add alias number
198192
// Change size to fit into 15 characters
199193
if (strlen(alias) > (MAX_ALIAS_SIZE - 1 - intsize))
200194
{
201195
alias[(MAX_ALIAS_SIZE - 1 - intsize)] = '\0';
202196
}
203-
else
204-
{
205-
alias[strlen(alias)] = '\0';
206-
}
207197
// Add a number at the end of the alias
208-
char *alias_copy = alias;
209-
sprintf(alias, "%s%d", alias_copy, num);
198+
char *end_pointer = &alias[strlen(alias)];
199+
sprintf(end_pointer, "%d", num);
210200
}
211201

212202
/******************************************************************************

test/tests_core/test_routing_table/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ void unittest_RoutingTB_AddNumToAlias(void)
197197
}
198198
TEST_ASSERT_TRUE(IS_ASSERT());
199199
END_TRY;
200+
TRY
201+
{
202+
char alias[MAX_ALIAS_SIZE] = "Dummy_App";
203+
RoutingTB_AddNumToAlias(alias, 100);
204+
}
205+
TEST_ASSERT_TRUE(IS_ASSERT());
206+
END_TRY;
207+
TRY
208+
{
209+
char alias[MAX_ALIAS_SIZE] = "Dummy_App";
210+
RoutingTB_AddNumToAlias(alias, 101);
211+
}
212+
TEST_ASSERT_TRUE(IS_ASSERT());
213+
END_TRY;
200214
}
201215

202216
NEW_TEST_CASE("check RoutingTB_AddNumToAlias return value");

0 commit comments

Comments
 (0)