curl-library
Re: Warnings: Derefencing pointer does break strict-aliasing rules
Date: Mon, 11 Jun 2012 17:30:10 +0200
2012/6/11 Daniel Stenberg <daniel_at_haxx.se>:
> On Mon, 11 Jun 2012, Marc Hoersken wrote:
>
>> thanks for the tip! I prepared a patch that fixes the warnings by using a
>> union, like you suggested.
>>
>> I tested it with my mingw32 build and winbuild VC environments. It would
>> be great if someone else could test it on the different Unix flavours.
>>
>> Please note the information provided in the patch file.
>
>
> Thanks! I took at look at it and ran it through the tests on my linux host
> too, and then pushed it...
>
Thanks Daniel. But it seems like the patch actually didn't fix the problem.
For some reason I didn't catch those warnings on my local build, but
my build system still reports those warnings in the autobuilds:
http://curl.haxx.se/dev/log.cgi?id=20120611135452-30673#prob1
ftp.c: In function 'ftp_state_use_port':
ftp.c:1260: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1094: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1089: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1086: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1151: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1148: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1147: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1233: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1237: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1239: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:1243: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
ftp.c:965: note: initialized from here
http://curl.haxx.se/dev/log.cgi?id=20120611135452-30673#prob13
connect.c: In function 'singleipconnect':
connect.c:381: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:382: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:390: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:391: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:405: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:406: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:412: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:413: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:443: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:440: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:439: warning: dereferencing pointer 'sock' does break
strict-aliasing rules
connect.c:265: note: initialized from here
I have attached another patch that tries to fix the problem, but it
seems like it is not possible without actually copying the data into a
new buffer. GCC is actually able to trace the pointer back to struct
Curl_sockaddr_storage which of course is not compatible to struct
sockaddr.
Applying the attached patch turns the warnings into the following:
ftp.c: In function 'ftp_state_use_port':
ftp.c:967: warning: ISO C90 forbids mixed declarations and code
ftp.c:1086: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1086: note: initialized from here
ftp.c:1089: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1089: note: initialized from here
ftp.c:1094: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1094: note: initialized from here
ftp.c:1147: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1147: note: initialized from here
ftp.c:1148: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1148: note: initialized from here
ftp.c:1151: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1151: note: initialized from here
ftp.c:1233: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1233: note: initialized from here
ftp.c:1237: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1237: note: initialized from here
ftp.c:1239: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1239: note: initialized from here
ftp.c:1243: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1243: note: initialized from here
ftp.c:1260: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
ftp.c:1260: note: initialized from here
connect.c: In function 'bindlocal':
connect.c:267: warning: ISO C90 forbids mixed declarations and code
connect.c: In function 'singleipconnect':
connect.c:381: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:381: note: initialized from here
connect.c:382: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:382: note: initialized from here
connect.c:390: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:390: note: initialized from here
connect.c:391: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:391: note: initialized from here
connect.c:405: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:405: note: initialized from here
connect.c:406: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:406: note: initialized from here
connect.c:412: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:412: note: initialized from here
connect.c:413: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:413: note: initialized from here
connect.c:439: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:439: note: initialized from here
connect.c:440: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:440: note: initialized from here
connect.c:443: warning: dereferencing pointer '({anonymous})' does
break strict-aliasing rules
connect.c:443: note: initialized from here
I did reproduce this on my Linux build system now, but I am unable to
fix this by modifying the assignments in ftp.c or connect.c.
I think the only way to solve this is to either change struct
Curl_sockaddr_storage or use memcpy to copy the data from the storage
variable into the local union.
More information can be found in this stackoverflow question:
http://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule
Paul, Daniel and everybody else, do you have any other idea?
Best regards,
Marc
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
- application/octet-stream attachment: 0002-connect.c-ftp.c-Fixed-dereferencing-pointer-breakin.patch