Discussion:
[bug-mailutils] Compiler warnings
Ken Brown
2017-04-27 17:50:13 UTC
Permalink
I'm getting the following compiler warnings on Cygwin with gcc-5.4.0:

system.c:122:30: warning: unused variable ‘auth_data’ [-Wunused-variable]
const struct mu_auth_data *auth_data = key;

copyfile.c:166:16: warning: cast from pointer to integer of different
size [-Wpointer-to-int-cast]
if (fchmod ((int) trans[0], mode))
^
copyfile.c:196:17: warning: cast from pointer to integer of different
size [-Wpointer-to-int-cast]
if (fchown ((int) trans[0], uid, gid))
^

The attached patch silences the warnings. I'm not sure whether the
patch to copyfile.c is correct; it seems strange to be casting a pointer
to an integer which is then used as a file descriptor. But I admit that
I haven't studied the code.

Ken
Sergey Poznyakoff
2017-04-27 18:33:35 UTC
Permalink
Post by Ken Brown
The attached patch silences the warnings. I'm not sure whether the
patch to copyfile.c is correct;
No, it is not. intptr_t and int are different types. In this case
trans[0] does indeed hold a file descriptor (int value).

Regards,
Sergey
Ken Brown
2017-04-27 20:58:23 UTC
Permalink
Post by Sergey Poznyakoff
Post by Ken Brown
The attached patch silences the warnings. I'm not sure whether the
patch to copyfile.c is correct;
No, it is not. intptr_t and int are different types.
Yes, I realize they're different types. Otherwise, my patch wouldn't
get rid of the compiler warning.

Do you have a different suggestion as to how to avoid the compiler
warning? I thought using intptr_t was the standard way of dealing with
this.

Regards,

Ken
Sergey Poznyakoff
2017-04-28 08:55:16 UTC
Permalink
Hi Ken,
Post by Ken Brown
Yes, I realize they're different types. Otherwise, my patch wouldn't
get rid of the compiler warning.
Do you have a different suggestion as to how to avoid the compiler
warning? I thought using intptr_t was the standard way of dealing
with this.
Well, yes (assuming C99, of course). For copyfile.c, the double
type-cast will do:

if (fchmod ((int) (intptr_t) trans[0], mode))

Another (and, arguably more portable) way would be to change the
mu_transport_t to point to a union { void *; int; }. I haven't
decided yet what way to choose.

Regards,
Sergey

Loading...