New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formdata.c:390:21: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] #608

Closed
ilor opened this Issue Jan 20, 2016 · 8 comments

Comments

Projects
None yet
5 participants
@ilor

ilor commented Jan 20, 2016

In a 32-bit build (originally when cross-compiling, but also visible after a quick ./configure CFLAGS=-m32), with GCC 4.8 / 4.9 I get the following warning:

formdata.c: In function 'FormAdd':
formdata.c:390:21: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
         array_state?(curl_off_t)array_value:va_arg(params, curl_off_t);

array_value is a 32-bit pointer, curl_off_t is a 64-bit integer. The warning is fixable by casting to intptr_t first, but I don't know the code enough to know if that hides a problem elsewhere; if array_value is used to pass a curl_off_t then there might be truncation.

Happens on:

$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
$ arm-linux-androideabi-gcc --version
arm-linux-androideabi-gcc (GCC) 4.9 20140827 (prerelease)
@ilor

This comment has been minimized.

ilor commented Jan 20, 2016

Issue happens on master and curl-7_46_0, seems to have been introduced by ca5f934 "formadd: support >2GB files on windows" for #425

@bagder

This comment has been minimized.

Member

bagder commented Jan 22, 2016

it's a tricky beast to remove...

@Stof25

This comment has been minimized.

Stof25 commented Feb 29, 2016

That exact same code causes a warning when compiled with Visual 2015. It complains that the cast from a char* to a bigger signed integer will bit extend the sign and probably cause incorrect behavior :

curl\lib\formdata.c(389): error C4826: Conversion from 'char *' to 'curl_off_t' is sign-extended. This may cause unexpected runtime behavior.

@jay

This comment has been minimized.

Member

jay commented Feb 29, 2016

That doesn't happen to me in Visual Studio even at warn 4 but I'm using earlier versions so that's probably why. Can't we solve this with a cast to (ptrdiff_t) first? like
(curl_off_t)(ptrdiff_t)foo
if foo <0
problem
else
current_form->contentslength = foo

@jay

This comment has been minimized.

Member

jay commented Feb 29, 2016

ah, I misread this. array_value is a char * and indeed we can have a curl_off_t larger than that or ptrdiff_t. Any truncation though is happening much earlier when (I assume) the user passes the curl_off_t as a char pointer though, see https://github.com/curl/curl/blob/curl-7_47_1/include/curl/curl.h#L1861
I'm not sure if in CURLFORM_ARRAY there's a way to pass a curl_off_t as value if the curl_off_t value is larger than what can fit in the actual char *value.

@captain-caveman2k

This comment has been minimized.

Member

captain-caveman2k commented Mar 18, 2016

Hi @jay,

If you've not already found this out - you need to use /Wall on in Visual Studio to see the warning that @Stof25 mentioned - which commit 7e312bd suppresses.

Kind Regards

Steve

@bagder

This comment has been minimized.

Member

bagder commented Mar 18, 2016

64-bit value cannot be used for CURLFORM_CONTENTLEN when set in a form array and compiled on a 32-bit platforms

I think we should document this shortcoming. and I think we should consider declaring CURLFORM_ARRAY a deprecated way of providing options.

I already have a plan (but only plans so far) to introduce a curl_formadd() replacement that takes an easy handle as as well (curl_easy_form() perhaps?), and it would probably make sense to not support CURLFORM_ARRAY in that, to simplify the code and avoid this 32/64 bit problem.

@captain-caveman2k

This comment has been minimized.

Member

captain-caveman2k commented Mar 19, 2016

Added issue 93 to KNOWN_BUGS in commit 2107a95.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.