From 5d90d8930e75d4a8d8e50a0c19de5c2b52f25add Mon Sep 17 00:00:00 2001 From: cschwinne Date: Mon, 7 Mar 2022 20:37:48 +0100 Subject: [PATCH] Fix non-0 terminated hostname str --- wled00/wled.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 9da278120e..a98116954a 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -62,18 +62,19 @@ void prepareHostname(char* hostname) hostname[pos] = '-'; pos++; } - // else do nothing - no leading hyphens and do not include hyphens for all other characters. - pC++; - } - // if the hostname is left blank, use the mac address/default mdns name - if (pos < 6) { - sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6); - } else { //last character must not be hyphen - while (pos > 0 && hostname[pos -1] == '-') { - hostname[pos -1] = 0; - pos--; - } + // else do nothing - no leading hyphens and do not include hyphens for all other characters. + pC++; + } + // if the hostname is left blank, use the mac address/default mdns name + if (pos < 6) { + sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6); + } else { //last character must not be hyphen + hostname[pos] = '\0'; // terminate string + while (pos > 0 && hostname[pos -1] == '-') { + hostname[pos -1] = '\0'; + pos--; } + } } //handle Ethernet connection event