Skip to content

Commit f3e3f58

Browse files
usermod udp_name_sync : properly initialize packet if segment name is empty
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 2082b01 commit f3e3f58

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

usermods/udp_name_sync/udp_name_sync.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ class UdpNameSync : public Usermod {
3636
byte udpOut[WLED_MAX_SEGNAME_LEN + 2];
3737
udpOut[0] = 2; // 0: wled notifier protocol, 1: warls protocol, 2 is free
3838

39-
if (strlen(segmentName) && !mainseg.name) { //name is back to null
40-
notifierUdp.beginPacket(broadcastIp, udpPort);
41-
strcpy(segmentName,"");
42-
DEBUG_PRINTLN(F("UdpNameSync: sending Null name"));
43-
notifierUdp.write( udpOut , 2);
44-
notifierUdp.endPacket();
45-
return;
39+
if (strlen(segmentName) && !mainseg.name) { // name cleared
40+
notifierUdp.beginPacket(broadcastIp, udpPort);
41+
segmentName[0] = '\0';
42+
DEBUG_PRINTLN(F("UdpNameSync: sending empty name"));
43+
udpOut[1] = 0; // explicit empty string
44+
notifierUdp.write(udpOut, 2);
45+
notifierUdp.endPacket();
46+
return;
4647
}
4748

4849
const char* curName = mainseg.name ? mainseg.name : "";

0 commit comments

Comments
 (0)