From: Lev Stipakov Date: Wed, 3 Oct 2018 17:21:21 +0000 (+0300) Subject: openvpnserv: clarify return values type X-Git-Tag: v2.5_beta1~419 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab9193c32b19e42a1847bd4f6cf967ea0e3293c8;p=thirdparty%2Fopenvpn.git openvpnserv: clarify return values type Functions openvpn_vsntprintf and openvpn_sntprintf return values of type int, but in reality it is always 0 or 1 (and -1 for snrptinf), which can be represented as boolean. To make code clearer, change return type to BOOL. Also use stdbool.h header instead of bool definition macros in automatic.c. Signed-off-by: Lev Stipakov Acked-by: Selva Nair Message-Id: <1538587281-3209-1-git-send-email-lstipakov@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17532.html Signed-off-by: Gert Doering --- diff --git a/src/openvpnserv/automatic.c b/src/openvpnserv/automatic.c index 89367fcf6..3f2ca345a 100644 --- a/src/openvpnserv/automatic.c +++ b/src/openvpnserv/automatic.c @@ -36,13 +36,9 @@ #include #include +#include #include -/* bool definitions */ -#define bool int -#define true 1 -#define false 0 - static SERVICE_STATUS_HANDLE service; static SERVICE_STATUS status = { .dwServiceType = SERVICE_WIN32_SHARE_PROCESS }; diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index 073e3939e..33a8097fb 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -31,7 +31,7 @@ static wchar_t win_sys_path[MAX_PATH]; * These are necessary due to certain buggy implementations of (v)snprintf, * that don't guarantee null termination for size > 0. */ -int +BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist) { int len = -1; @@ -42,18 +42,19 @@ openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist) } return (len >= 0 && (size_t)len < size); } -int + +BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...) { va_list arglist; - int len = -1; + BOOL res = FALSE; if (size > 0) { va_start(arglist, format); - len = openvpn_vsntprintf(str, size, format, arglist); + res = openvpn_vsntprintf(str, size, format, arglist); va_end(arglist); } - return len; + return res; } static DWORD @@ -65,7 +66,7 @@ GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_v if (status == ERROR_FILE_NOT_FOUND && default_value) { size_t len = size/sizeof(data[0]); - if (openvpn_sntprintf(data, len, default_value) > 0) + if (openvpn_sntprintf(data, len, default_value)) { status = ERROR_SUCCESS; } diff --git a/src/openvpnserv/service.h b/src/openvpnserv/service.h index c6092b85f..d7b7b3fb4 100644 --- a/src/openvpnserv/service.h +++ b/src/openvpnserv/service.h @@ -82,9 +82,9 @@ VOID WINAPI ServiceStartAutomatic(DWORD argc, LPTSTR *argv); VOID WINAPI ServiceStartInteractiveOwn(DWORD argc, LPTSTR *argv); VOID WINAPI ServiceStartInteractive(DWORD argc, LPTSTR *argv); -int openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist); +BOOL openvpn_vsntprintf(LPTSTR str, size_t size, LPCTSTR format, va_list arglist); -int openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...); +BOOL openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...); DWORD GetOpenvpnSettings(settings_t *s);