# [PATCH] imap-send.c: fix pointer to be const

6 messages from 2009-10-28 to 2009-10-29. Participants: Vietor Liu, Junio C Hamano, Michael J Gruber.
Thread: https://gitlist.dev/t/21395

## Vietor Liu, 2009-10-28 05:09

Subject: [PATCH] imap-send.c: fix pointer to be const
Message-ID: <1256706591-2763-1-git-send-email-vietor@vxwo.org>
URL: https://gitlist.dev/e/1256706591-2763-1-git-send-email-vietor%40vxwo.org

```
Fixes some compiler warnings:
imap-send.c: In function ‘ssl_socket_connect’:
warning: assignment discards qualifiers from pointer target type

Signed-off-by: Vietor Liu <vietor@vxwo.org>
---
 imap-send.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/imap-send.c b/imap-send.c
index 3847fd1..10dd025 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -273,7 +273,7 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
 	fprintf(stderr, "SSL requested but SSL support not compiled in\n");
 	return -1;
 #else
-	SSL_METHOD *meth;
+	const SSL_METHOD *meth;
 	SSL_CTX *ctx;
 	int ret;
 
-- 
1.6.5.2

```

## Junio C Hamano, 2009-10-28 06:26

Subject: Re: [PATCH] imap-send.c: fix pointer to be const
Message-ID: <7vk4ygxce6.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk4ygxce6.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1256706591-2763-1-git-send-email-vietor@vxwo.org>

```
Vietor Liu <vietor@vxwo.org> writes:

> Fixes some compiler warnings:
> imap-send.c: In function ‘ssl_socket_connect’:
> warning: assignment discards qualifiers from pointer target type
>
> Signed-off-by: Vietor Liu <vietor@vxwo.org>

I do not quite understand.  This variable gets assigned the return values
from TLSv1_method() or SSLv23_method(), but the copy of ssl.h I have
declares them as:

    SSL_METHOD *SSLv23_method(void);	/* SSLv3 but can rollback to v2 */
    SSL_METHOD *TLSv1_method(void);		/* TLSv1.0 */

We would need to explain this change a bit better.

>  imap-send.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/imap-send.c b/imap-send.c
> index 3847fd1..10dd025 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -273,7 +273,7 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
>  	fprintf(stderr, "SSL requested but SSL support not compiled in\n");
>  	return -1;
>  #else
> -	SSL_METHOD *meth;
> +	const SSL_METHOD *meth;
>  	SSL_CTX *ctx;
>  	int ret;
>  
> -- 
> 1.6.5.2

```

## Vietor Liu, 2009-10-28 07:05

Subject: Re: [PATCH] imap-send.c: fix pointer to be const
Message-ID: <1256713526.3333.0.camel@localhost.localdomain>
URL: https://gitlist.dev/e/1256713526.3333.0.camel%40localhost.localdomain
In-Reply-To: <7vk4ygxce6.fsf@alter.siamese.dyndns.org>

```
On Tue, 2009-10-27 at 23:26 -0700, Junio C Hamano wrote:
> Vietor Liu <vietor@vxwo.org> writes:
> 
> > Fixes some compiler warnings:
> > imap-send.c: In function ‘ssl_socket_connect’:
> > warning: assignment discards qualifiers from pointer target type
> >
> > Signed-off-by: Vietor Liu <vietor@vxwo.org>
> 
> I do not quite understand.  This variable gets assigned the return values
> from TLSv1_method() or SSLv23_method(), but the copy of ssl.h I have
> declares them as:
> 
>     SSL_METHOD *SSLv23_method(void);	/* SSLv3 but can rollback to v2 */
>     SSL_METHOD *TLSv1_method(void);		/* TLSv1.0 */

1. openssl-devel-1.0.0-0.10

const SSL_METHOD *SSLv23_method(void);	/* SSLv3 but can rollback to v2
*/
const SSL_METHOD *TLSv1_method(void);		/* TLSv1.0 */


2. http://www.openssl.org/docs/ssl/ssl.html

const SSL_METHOD *SSLv2_method(void);
        
        Constructor for the SSLv2 SSL_METHOD structure for combined
        client and server.
const SSL_METHOD *TLSv1_method(void);
        
        Constructor for the TLSv1 SSL_METHOD structure for combined
        client and server.

3. it maybe fixes warnings for other version.

```

## Michael J Gruber, 2009-10-28 13:33

Subject: Re: [PATCH] imap-send.c: fix pointer to be const
Message-ID: <4AE8482F.7020807@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4AE8482F.7020807%40drmicha.warpmail.net
In-Reply-To: <1256713526.3333.0.camel@localhost.localdomain>

```
Vietor Liu venit, vidit, dixit 28.10.2009 08:05:
> On Tue, 2009-10-27 at 23:26 -0700, Junio C Hamano wrote:
>> Vietor Liu <vietor@vxwo.org> writes:
>>
>>> Fixes some compiler warnings:
>>> imap-send.c: In function ‘ssl_socket_connect’:
>>> warning: assignment discards qualifiers from pointer target type
>>>
>>> Signed-off-by: Vietor Liu <vietor@vxwo.org>
>>
>> I do not quite understand.  This variable gets assigned the return values
>> from TLSv1_method() or SSLv23_method(), but the copy of ssl.h I have
>> declares them as:
>>
>>     SSL_METHOD *SSLv23_method(void);	/* SSLv3 but can rollback to v2 */
>>     SSL_METHOD *TLSv1_method(void);		/* TLSv1.0 */
> 
> 1. openssl-devel-1.0.0-0.10
> 
> const SSL_METHOD *SSLv23_method(void);	/* SSLv3 but can rollback to v2
> */
> const SSL_METHOD *TLSv1_method(void);		/* TLSv1.0 */
> 
> 
> 2. http://www.openssl.org/docs/ssl/ssl.html
> 
> const SSL_METHOD *SSLv2_method(void);
>         
>         Constructor for the SSLv2 SSL_METHOD structure for combined
>         client and server.
> const SSL_METHOD *TLSv1_method(void);
>         
>         Constructor for the TLSv1 SSL_METHOD structure for combined
>         client and server.
> 
> 3. it maybe fixes warnings for other version.

No const here with openssl 0.9.8k. I think major distros will switch to
1.0.0 with their next major release (e.g. Fedora 12 will have it by the
end of this year).

Since this is only about warnings, maybe git 1.7.0 is the right time
frame to adjust this to the upcoming standard?

Michael

```

## Junio C Hamano, 2009-10-28 17:56

Subject: Re: [PATCH] imap-send.c: fix pointer to be const
Message-ID: <7vhbtjo10s.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhbtjo10s.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4AE8482F.7020807@drmicha.warpmail.net>

```
Michael J Gruber <git@drmicha.warpmail.net> writes:

> Since this is only about warnings, maybe git 1.7.0 is the right time
> frame to adjust this to the upcoming standard?

This does not look like "one group wants this way, but the others want
differently.  We have to pick one and sacrifice the other because it is
impossible to have it both ways"; there is no excuse to bring up 1.7.0 for
something like this.

Doesn't inclusing "ssl.h" give us some indication whether "const" is
needed to allow us to use #if/#else/#endif in order to compile with
headers from either versions?  I.e. something like...

diff --git a/imap-send.c b/imap-send.c
index 3847fd1..a199db8 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -273,7 +273,11 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
 	fprintf(stderr, "SSL requested but SSL support not compiled in\n");
 	return -1;
 #else
+#if (OPENSSL_VERSION_NUMBER >= 0x1000000fL)
+	const SSL_METHOD *meth;
+#else
 	SSL_METHOD *meth;
+#endif
 	SSL_CTX *ctx;
 	int ret;
 

```

## Vietor Liu, 2009-10-29 00:13

Subject: Re: [PATCH] imap-send.c: fix pointer to be const
Message-ID: <1256775193.2040.6.camel@localhost.localdomain>
URL: https://gitlist.dev/e/1256775193.2040.6.camel%40localhost.localdomain
In-Reply-To: <7vhbtjo10s.fsf@alter.siamese.dyndns.org>

```
On Wed, 2009-10-28 at 10:56 -0700, Junio C Hamano wrote:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
> > Since this is only about warnings, maybe git 1.7.0 is the right time
> > frame to adjust this to the upcoming standard?
> 
> This does not look like "one group wants this way, but the others want
> differently.  We have to pick one and sacrifice the other because it is
> impossible to have it both ways"; there is no excuse to bring up 1.7.0 for
> something like this.
> 
> Doesn't inclusing "ssl.h" give us some indication whether "const" is
> needed to allow us to use #if/#else/#endif in order to compile with
> headers from either versions?  I.e. something like...
> 
> diff --git a/imap-send.c b/imap-send.c
> index 3847fd1..a199db8 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -273,7 +273,11 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
>  	fprintf(stderr, "SSL requested but SSL support not compiled in\n");
>  	return -1;
>  #else
> +#if (OPENSSL_VERSION_NUMBER >= 0x1000000fL)
> +	const SSL_METHOD *meth;
> +#else
>  	SSL_METHOD *meth;
> +#endif
>  	SSL_CTX *ctx;
>  	int ret;
>  

It's better than my patch, thanks.

```
