Skip to content

[OpenSSL]:'may be used uninitialized' warning #1083

Closed

Description

@rahmanih

Hi,
when configuring libssh2 with high optimization, the gcc throws the following error:

/home/rahmanih/github/libssh2/src/openssl.c:381:19: warning: ‘type’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  381 |         *out_type = type;
      |         ~~~~~~~~~~^~~~~~

regards
Haithem.

Activity

  1. changed the title [-][OpenSSL]:'may be used uninitialized' warining[/-] [+][OpenSSL]:'may be used uninitialized' warning[/+] on Jun 4, 2023
  2. vszakats commented on Jun 4, 2023

    @vszakats
    Member

    It's fairly non-obvious to find a valid reason behind this one, unless it is a false-positive in both MSVC (where we silence it already) and gcc.

    Does this patch silence it for you?:

    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

    and this one?:

    diff --git a/src/openssl.c b/src/openssl.c
    index 556176cf..197cdca9 100644
    --- a/src/openssl.c
    +++ b/src/openssl.c
    @@ -368,11 +368,7 @@ _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
    +        type = (libssh2_curve_type)0;  /* silence 'uninitialized' warnings */
             ret = -1;
         }
     
  3. vszakats commented on Jun 4, 2023

    @vszakats
    Member

    Can you tell us your gcc version and configuration options?

  4. added a commit that references this issue on Jun 5, 2023
    009d7fe
  5. added a commit that references this issue on Jul 16, 2023
    b462e03
  6. added a commit that references this issue on Mar 28, 2024
    8b92499
  7. added a commit that references this issue on Jul 14, 2024
    d48f27c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions