From b53c8a758e358057b342b012d2ce14fc078a93d1 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 11 Jun 2018 12:06:54 -0400 Subject: [PATCH] Fix display of assigned IPs when IPv4 address is absent - In tray info do not skip the address when v4 ip is absent - When combining two strings do not add the separator (comma) if either is empty. Signed-off-by: Selva Nair --- misc.c | 8 +++++--- tray.c | 12 +++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/misc.c b/misc.c index 8fbdb0e..fad1a48 100644 --- a/misc.c +++ b/misc.c @@ -479,7 +479,7 @@ validate_input(const WCHAR *input, const WCHAR *exclude) return (wcspbrk(input, exclude) == NULL); } -/* Concatenate two wide strings with a separator */ +/* Concatenate two wide strings with a separator -- if either string is empty separator not added */ void wcs_concat2(WCHAR *dest, int len, const WCHAR *src1, const WCHAR *src2, const WCHAR *sep) { @@ -488,10 +488,12 @@ wcs_concat2(WCHAR *dest, int len, const WCHAR *src1, const WCHAR *src2, const WC if (!dest || len == 0) return; - if (src1 && src2 && src2[0]) + if (src1 && src2 && src1[0] && src2[0]) n = swprintf(dest, len, L"%s%s%s", src1, sep, src2); - else if (src1) + else if (src1 && src1[0]) n = swprintf(dest, len, L"%s", src1); + else if (src2 && src2[0]) + n = swprintf(dest, len, L"%s", src2); if (n < 0 || n >= len) /*swprintf failed */ n = 0; diff --git a/tray.c b/tray.c index 808eb1b..1e1dc2e 100644 --- a/tray.c +++ b/tray.c @@ -280,13 +280,11 @@ SetTrayIcon(conn_state_t state) _tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _countof(msg) - _tcslen(msg) - 1); _tcsncat(msg, time, _countof(msg) - _tcslen(msg) - 1); - if ( _tcslen(c->ip) > 0) { - /* concatenate ipv4 and ipv6 addresses into one string */ - WCHAR ip[64]; - wcs_concat2(ip, _countof(ip), c->ip, c->ipv6, L", "); - WCHAR *assigned_ip = LoadLocalizedString(IDS_TIP_ASSIGNED_IP, ip); - _tcsncat(msg, assigned_ip, _countof(msg) - _tcslen(msg) - 1); - } + /* concatenate ipv4 and ipv6 addresses into one string */ + WCHAR ip[64]; + wcs_concat2(ip, _countof(ip), c->ip, c->ipv6, L", "); + WCHAR *assigned_ip = LoadLocalizedString(IDS_TIP_ASSIGNED_IP, ip); + _tcsncat(msg, assigned_ip, _countof(msg) - _tcslen(msg) - 1); } icon_id = ID_ICO_CONNECTING;