Subject: Re: release time?

Re: release time?

From: Alexander Lamaison <swish_at_lammy.co.uk>
Date: Thu, 21 Jan 2010 19:53:28 +0000

2010/1/21 Peter Stuge <peter_at_stuge.se>:
>> +            } else if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_FAILURE) {
>> +                _libssh2_debug(session, LIBSSH2_TRACE_AUTH,
>> +                               "Password authentication failed");
>> +                LIBSSH2_FREE(session, session->userauth_pswd_data);
>> +                session->userauth_pswd_data = NULL;
>> +                session->userauth_pswd_state = libssh2_NB_state_idle;
>> +                libssh2_error(session,
>> +                              LIBSSH2_ERROR_AUTHENTICATION_FAILED,
>> +                              "Authentication failed (username/password)",
>> +                              0);
>> +                return -1;
>
>
> Would anyone veto changes that reduce mindless code duplication such
> as above with the use of forward gotos to the end of functions?

Rather than gotos, how about a helper function e.g.:

...
    } else if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_FAILURE) {
        return auth_fail(session, "Authentication failed (username/password)");
...

static int auth_fail(LIBSSH2_SESSION* session, const char* message)
{
    _libssh2_debug(session, LIBSSH2_TRACE_AUTH, message);
    LIBSSH2_FREE(session, session->userauth_pswd_data);
    session->userauth_pswd_data = NULL;
    session->userauth_pswd_state = libssh2_NB_state_idle;
    libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, message, 0);
    return -1;
}

Or am I missing the need for gotos (not got the code in front of me)?

Alex
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-01-21