From 236250492e06aeeb1bb875eb708079a6fda6937f Mon Sep 17 00:00:00 2001 From: Hyeongjun Kim Date: Tue, 31 Mar 2026 22:44:08 +0900 Subject: [PATCH] Fixed off-by-one bug in gateway main() causing duplicate I-Am broadcast (#1289) When Routed_Device_Index reached MAX_NUM_DEVICES, Get_Routed_Device_Object() returned NULL without updating iCurrent_Device_Idx, causing Send_I_Am() to broadcast the previous device's I-Am again. * Initialize Routed_Device_Index to 1 (first routed device index) * Move increment after Send_I_Am() to prevent out-of-bounds access Signed-off-by: kimhyeongjun --- apps/gateway/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gateway/main.c b/apps/gateway/main.c index 3284b0cf..4544c5bc 100644 --- a/apps/gateway/main.c +++ b/apps/gateway/main.c @@ -61,7 +61,7 @@ int DNET_list[2] = { static const char *BACnet_Version = BACNET_VERSION_TEXT; /* routed devices - I-Am on startup */ -static unsigned Routed_Device_Index; +static unsigned Routed_Device_Index = 1; /** Initialize the Device Objects and each of the child Object instances. * @param first_object_instance Set the first (gateway) Device to this @@ -278,10 +278,10 @@ int main(int argc, char *argv[]) } handler_cov_task(); if (Routed_Device_Index < MAX_NUM_DEVICES) { - Routed_Device_Index++; Get_Routed_Device_Object(Routed_Device_Index); /* broadcast an I-Am for each routed Device now */ Send_I_Am(&Handler_Transmit_Buffer[0]); + Routed_Device_Index++; } } /* Dummy return */