Skip to content

Commit 23dd45a

Browse files
Merge pull request #476 from Luos-io/fix/no_service
Allow node to properly work without any services running
2 parents 4ed1943 + 5689da2 commit 23dd45a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

engine/core/src/service.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ void Service_ClearId(void)
120120
******************************************************************************/
121121
uint16_t Service_GetIndex(service_t *service)
122122
{
123+
if (service_ctx.number == 0)
124+
{
125+
// We don't have any service just return 0 by default.
126+
return 0;
127+
}
123128
LUOS_ASSERT((service >= service_ctx.list) && (service < &service_ctx.list[service_ctx.number]));
124129
return ((uintptr_t)service - (uintptr_t)service_ctx.list) / sizeof(service_t);
125130
}

tool_services/gate/TinyJSON/convert.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,11 +1049,13 @@ void Convert_RoutingTableData(service_t *service)
10491049

10501050
json_ptr += strlen(json_ptr);
10511051
i++;
1052+
bool find_service = false;
10521053
// Services loop
10531054
while (i < last_entry)
10541055
{
10551056
if (routing_table[i].mode == SERVICE)
10561057
{
1058+
find_service = true;
10571059
// Create service description
10581060
sprintf(json_ptr, "{\"type\":\"%s\",\"id\":%d,\"alias\":\"%s\"},", Convert_StringFromType(routing_table[i].type), routing_table[i].id, routing_table[i].alias);
10591061
json_ptr += strlen(json_ptr);
@@ -1062,8 +1064,11 @@ void Convert_RoutingTableData(service_t *service)
10621064
else
10631065
break;
10641066
}
1065-
// remove the last "," char
1066-
*(--json_ptr) = '\0';
1067+
if (find_service)
1068+
{
1069+
// remove the last "," char
1070+
*(--json_ptr) = '\0';
1071+
}
10671072
sprintf(json_ptr, "]},");
10681073
json_ptr += strlen(json_ptr);
10691074
}

0 commit comments

Comments
 (0)