From 8b92499940cc930b61ab4c966ff5acc54900bb3f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 5 Jun 2023 19:59:53 +0000 Subject: [PATCH] src: improve MSVC C4701 warning fix Simplify the code to avoid this warning. This might also help avoiding it with other compilers (e.g. gcc?). Improves 02f2700a61157ce5a264319bdb80754c92a40a24 #876 Might fix #1083 Closes #1086 --- src/kex.c | 12 +++--------- src/openssl.c | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/kex.c b/src/kex.c index 5a9f4882..d4be2d4a 100644 --- a/src/kex.c +++ b/src/kex.c @@ -1685,7 +1685,6 @@ do { \ static int kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) { - int ret = 0; libssh2_curve_type type; if(!name) @@ -1698,19 +1697,14 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) else if(strcmp(name, "ecdh-sha2-nistp521") == 0) type = LIBSSH2_EC_CURVE_NISTP521; else { -/* silence: - warning C4701: potentially uninitialized local variable 'type' used */ -#if defined(_MSC_VER) - type = (libssh2_curve_type)0; -#endif - ret = -1; + return -1; } - if(ret == 0 && out_type) { + if(out_type) { *out_type = type; } - return ret; + return 0; } diff --git a/src/openssl.c b/src/openssl.c index 556176cf..c232d823 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -355,7 +355,6 @@ int _libssh2_ecdsa_curve_type_from_name(const char *name, libssh2_curve_type *out_type) { - int ret = 0; libssh2_curve_type type; if(!name || strlen(name) != 19) @@ -368,19 +367,14 @@ _libssh2_ecdsa_curve_type_from_name(const char *name, else if(strcmp(name, "ecdsa-sha2-nistp521") == 0) type = LIBSSH2_EC_CURVE_NISTP521; else { -/* silence: - warning C4701: potentially uninitialized local variable 'type' used */ -#if defined(_MSC_VER) - type = (libssh2_curve_type)0; -#endif - ret = -1; + return -1; } - if(ret == 0 && out_type) { + if(out_type) { *out_type = type; } - return ret; + return 0; } /* _libssh2_ecdsa_curve_name_with_octal_new