[openssl-dev] Under-utilization of "const" in prototyping?

Viktor Dukhovni openssl-users at dukhovni.org
Fri Dec 5 12:15:24 EST 2014


On Fri, Dec 05, 2014 at 05:07:04PM +0100, Kurt Roeckx wrote:

> On Fri, Dec 05, 2014 at 10:40:07AM -0500, Daniel Kahn Gillmor wrote:
> > (of course it would probably end up modifying some public
> > interfaces, so it would need to take effect publicly during an API change).
> 
> Adding const to a function shouldn't be a problem for C.  It would
> be for C++.

Actually, it can be a problem with C also.  Replacing "char **" in
a function prototype with "const char **" changes the API.

Postfix has #ifdefs for a previous "constification" effort in OpenSSL:

    SSL_SESSION *tls_session_activate(const char *session_data, int session_data_len)
    {
    #if (OPENSSL_VERSION_NUMBER < 0x0090707fL)
    #define BOGUS_CONST
    #else
    #define BOGUS_CONST const
    #endif
	SSL_SESSION *session;
	BOGUS_CONST unsigned char *ptr;

	/*
	 * Activate the SSL_SESSION object.
	 */
	ptr = (BOGUS_CONST unsigned char *) session_data;
	session = d2i_SSL_SESSION((SSL_SESSION **) 0, &ptr, session_data_len);
	if (!session)
	    tls_print_errors();

	return (session);
    }

--
	Viktor.


More information about the openssl-dev mailing list