cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: VC9 libcurl compiler warnings (64 bit only)

From: Adam Light <aclight_at_gmail.com>
Date: Sat, 24 Jul 2010 14:54:14 -0700

On Sat, Jul 24, 2010 at 1:58 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Fri, 23 Jul 2010, Adam Light wrote:
>> connect.c(1084) : warning C4244: '=' : conversion from 'curl_socket_t'
>> to 'long', possible loss of data
>> This seems to be a problem because curl_socket_t is defined as UINT_PTR
>> and
>> UINT_PTR is defined, in x64, as: typedef unsigned __int64 UINT_PTR
>>
>> If param_longp is holding a pointer, which it appears to be doing, it
>> needs to be large enough to actually hold the pointer.
>
> param_longp is a 'long *' in that function. That is a pointer. It can point
> to data. It points to a long.
>
> A 'curl_socket_t' is typedef'ed to be a SOCKET type on Windows. Isn't that
> still a 32bit variable? Are you saying that SOCKET is 64 bit type in 64 bit
> Windows?

Right. In WinSock.h, there is this:
     typedef UINT_PTR SOCKET;
and in BaseTsd.h, there is this:
    #if defined(_WIN64)
        typedef __int64 INT_PTR, *PINT_PTR;
        typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
        ....

So SOCKET is a 64 bit type in 64 bit windows.

>
>> #2-4:
>> curl_addrinfo.c(154) : warning C4267: '=' : conversion from 'size_t'
>> to 'curl_socklen_t', possible loss of data
>
> Does it help if we add a typecast (and a comment) ?
>

Yes, changing line 154 of curl_addrinfo.c from
    ca->ai_addrlen = ai->ai_addrlen;
to
    ca->ai_addrlen = (curl_socklen_t)ai->ai_addrlen;
does eliminate the warning.

It looks like ai->ai_addrlen shouldn't ever be very big, so this should be ok.

>> file.c(556) : warning C4267: 'function' : conversion from 'size_t' to
>> 'unsigned int', possible loss of data
>
> Is your read() returning anything else but ssize_t ? If not, what exactly
> does your ssize_t get typedef'ed to in the libcurl headers? If it does, what
> _does_ your read() return?
>
Actually I think the problem is with the last parameter to the read()
function. bytestoread is a size_t, which on Win64 is an unsigned
__int64. However the last parameter of read() is an unsigned int type
(see <http://msdn.microsoft.com/en-us/library/wyssk1bs(VS.90).aspx>).
So the conversion of the last parameter when calling read() produces
the warning. Practically speaking this shouldn't cause a problem
since from line 555 of file.c, bytestoread can never be larger than
BUFSIZE-1, and BUFSIZE is #define'ed as CURL_MAX_WRITE_SIZE, which is
#define'ed in curl.h as 16384. Though it's possible that someone
would #define CURL_MAX_WRITE_SIZE to something much larger.

>> http.c(1072) : warning C4244: '+=' : conversion from '__int64' to
>> 'long', possible loss of data
>
> I committed and a pushed a fix for this just now that simply typecasts the
> added value to a long.

I've confirmed that your change did eliminate this warning.

Thanks for taking a look at these.

Adam
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-07-24