Skip to content

Commit 5d90d89

Browse files
committed
Fix non-0 terminated hostname str
1 parent b01309c commit 5d90d89

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

wled00/wled.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ void prepareHostname(char* hostname)
6262
hostname[pos] = '-';
6363
pos++;
6464
}
65-
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
66-
pC++;
67-
}
68-
// if the hostname is left blank, use the mac address/default mdns name
69-
if (pos < 6) {
70-
sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6);
71-
} else { //last character must not be hyphen
72-
while (pos > 0 && hostname[pos -1] == '-') {
73-
hostname[pos -1] = 0;
74-
pos--;
75-
}
65+
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
66+
pC++;
67+
}
68+
// if the hostname is left blank, use the mac address/default mdns name
69+
if (pos < 6) {
70+
sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6);
71+
} else { //last character must not be hyphen
72+
hostname[pos] = '\0'; // terminate string
73+
while (pos > 0 && hostname[pos -1] == '-') {
74+
hostname[pos -1] = '\0';
75+
pos--;
7676
}
77+
}
7778
}
7879

7980
//handle Ethernet connection event

0 commit comments

Comments
 (0)