[Openvpn-devel] options.c: fix msvc build error

Message ID 20210607182602.273-1-lstipakov@gmail.com
State Superseded
Headers show
Series
  • [Openvpn-devel] options.c: fix msvc build error
Related show

Commit Message

Lev Stipakov June 7, 2021, 6:26 p.m.
From: Lev Stipakov <lev@openvpn.net>

Commit b7fe49c ("Do not require CA when peer-fingerprint is used") broke
msvc build by adding #ifdef within msg() macro call.

    options.c(2074,1): error C2121: '#': invalid character: possibly the result of a macro expansion
    options.c(2074,1): error C2146: syntax error: missing ')' before identifier 'ifndef'
    options.c(2074,1): error C2059: syntax error: ')'

Fix by moving #ifdef outside of msg().

Reported-by: Samuli Seppänen <samuli@openvpn.net>
Signed-off-by: Lev Stipakov <lev@openvpn.net>
---
 src/openvpn/options.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Selva Nair June 7, 2021, 7:38 p.m. | #1
On Mon, Jun 7, 2021 at 2:56 PM Lev Stipakov <lstipakov@gmail.com> wrote:
>
> From: Lev Stipakov <lev@openvpn.net>
>
> Commit b7fe49c ("Do not require CA when peer-fingerprint is used") broke
> msvc build by adding #ifdef within msg() macro call.
>
>     options.c(2074,1): error C2121: '#': invalid character: possibly the result of a macro expansion
>     options.c(2074,1): error C2146: syntax error: missing ')' before identifier 'ifndef'
>     options.c(2074,1): error C2059: syntax error: ')'
>
> Fix by moving #ifdef outside of msg().
>
> Reported-by: Samuli Seppänen <samuli@openvpn.net>
> Signed-off-by: Lev Stipakov <lev@openvpn.net>
> ---
>  src/openvpn/options.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/openvpn/options.c b/src/openvpn/options.c
> index 6bbe5c15..606e6903 100644
> --- a/src/openvpn/options.c
> +++ b/src/openvpn/options.c
> @@ -2067,11 +2067,12 @@ check_ca_required(const struct options *options)
>          return;
>      }
>
> -    msg(M_USAGE, "You must define CA file (--ca)"
> +    const char* str = "You must define CA file (--ca)"
>  #ifndef ENABLE_CRYPTO_MBEDTLS
>          " or CA path (--capath)"
>  #endif
> -        " and/or peer fingeprint verification " "(--peer-fingerprint)");
> +        " and/or peer fingeprint verification " "(--peer-fingerprint)";
> +    msg(M_USAGE, str);
>  }

I forgot msg was a macro... Surprisingly, gcc preprocessor can handle this.

Let's also use this opportunity to fix the typo "fingeprint" and
remove the unneeded " " before (--peer-fingerprint). If it could be
done at commit time?

Acked-by: selva.nair@gmail.com

Patch

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 6bbe5c15..606e6903 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -2067,11 +2067,12 @@  check_ca_required(const struct options *options)
         return;
     }
 
-    msg(M_USAGE, "You must define CA file (--ca)"
+    const char* str = "You must define CA file (--ca)"
 #ifndef ENABLE_CRYPTO_MBEDTLS
         " or CA path (--capath)"
 #endif
-        " and/or peer fingeprint verification " "(--peer-fingerprint)");
+        " and/or peer fingeprint verification " "(--peer-fingerprint)";
+    msg(M_USAGE, str);
 }
 
 static void