12 Jul, 2010, ralgith wrote in the 1st comment:
Votes: 0
Getting the following warnings:
Quote
$ make
g++ -g2 -Os -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls -Wconversion -pedantic -c -o imc.o imc.c
cc1plus: warnings being treated as errors
imc.c:100: error: deprecated conversion from string constant to char*
imc.c:100: error: deprecated conversion from string constant to char*
imc.c:100: error: deprecated conversion from string constant to char*
imc.c:100: error: deprecated conversion from string constant to char*
imc.c: In function bool imc_readconfig():
imc.c:5511: error: conversion to short int from int may alter its value
imc.c: In function void imc_hotboot_recover():
imc.c:5835: error: conversion to short unsigned int from int may alter its value
imc.c: In function bool imc_startup_port():
imc.c:5895: error: conversion to short unsigned int from int may alter its value
make: *** [imc.o] Error 1


Now, I've been able to fix all of them myself, except the 5895 line.

To lay out what I've done so far:
I started off by changing the define for struct imc_siteinfo's port from short to unsigned short, since you can't have negative ports.
For 5511 and 5835 I just typecasted them as (unsigned short int)atoi()
However, in 5895 we're using htons, which already returns an unsigned short int, and is passed (with my change in imc.h) an unsigned short as well.
So why should it still be dumping an error? I'm not really familiar with htons, hence asking.
As for the string conversions, that was an easy one. Changing from char *const to const char * solved that.

Now trying make:
Quote
$ make
g++ -g2 -Os -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls -Wconversion -pedantic -c -o imc.o imc.c
cc1plus: warnings being treated as errors
imc.c: In function bool imc_startup_port():
imc.c:5895: error: conversion to short unsigned int from int may alter its value
make: *** [imc.o] Error 1


I'm using the following:
Quote
$ make –version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

$ g++ –version
g++ (GCC) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ln –version
ln (GNU coreutils) 7.5
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>;.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Parker and David MacKenzie.


Same error on my production server, which uses a different 4.x.x GCC.
Now, I can compile and use the program if I remove -Wconversion from the Makefile's compiler flags, but that kind of defeats the purpose yes?
Besides, the whole point of me working on this is so that I can make the changes available to others.
12 Jul, 2010, David Haley wrote in the 2nd comment:
Votes: 0
Could you post the relevant lines of code please?
12 Jul, 2010, ralgith wrote in the 3rd comment:
Votes: 0
sa.sin_port        = htons( siteinfo->port );


sa is:
struct sockaddr_in sa;


And siteinfo is a struct site_info from imc.h where I've done:
unsigned short port;            /* Port the server listens on */
12 Jul, 2010, ralgith wrote in the 4th comment:
Votes: 0
And just to clarify, I have tried compiling with the –save-temps flag and grepping the imc.ii for htons I got:
Quote
extern uint16_t htons (uint16_t __hostshort)

Then grepping for typedef unsigned short:
Quote
typedef unsigned short int __u_short;
typedef unsigned short int __uint16_t;
typedef unsigned short int ushort;
typedef unsigned short int sa_family_t;
typedef unsigned short int uint16_t;
typedef unsigned short int uint_least16_t;
typedef unsigned short __u16;
typedef unsigned short umode_t;
typedef unsigned short __kernel_mode_t;
typedef unsigned short __kernel_nlink_t;
typedef unsigned short __kernel_ipc_pid_t;
typedef unsigned short __kernel_uid_t;
typedef unsigned short __kernel_gid_t;
typedef unsigned short __kernel_uid16_t;
typedef unsigned short __kernel_gid16_t;
typedef unsigned short __kernel_old_uid_t;
typedef unsigned short __kernel_old_gid_t;
typedef unsigned short __kernel_old_dev_t;
{ typedef unsigned short __type; };
typedef unsigned short mask;


Which clearly shows uint16_t being defined as an unsigned short int.
So this SHOULD be correct.

What do you guys think, bad compiler warning?
12 Jul, 2010, David Haley wrote in the 5th comment:
Votes: 0
ralgith said:
sa.sin_port        = htons( siteinfo->port );

This is not answering the question directly, but this value should not be converted from host to network order. Try removing htons and see what the compiler says.
12 Jul, 2010, ralgith wrote in the 6th comment:
Votes: 0
And why shouldn't it be? As I understand it, htons should always be used for safety. Systems already IN network order just return the original port number and systems not in it return it converted. Have I misunderstood the documentation for htons?
12 Jul, 2010, David Haley wrote in the 7th comment:
Votes: 0
You need to use it to convert data sent across a network. The port is read from a configuration file, and is not network data. Why would you "convert" data for a network when you're not actually sending or receiving it over the network?

That said – it turns out that 'bind' wants the port in network order, even though it's not actually being sent over the network. So you were right, but for the wrong reason, and I was wrong, but not according to the htons documentation. :tongue:

Going back to the original problem, the warning as such doesn't make any sense. But when I compile the version of the Liberty server that I have – which includes the htons call – I don't get the warning you do. Where did you get your code, and what exactly have you changed with it? Can you make it available somewhere along with a link to the original download?
12 Jul, 2010, ralgith wrote in the 8th comment:
Votes: 0
I downloaded it here. Just today. Literally a half hour or so before posting.
Thats why I included my g++ version and everything.

Now, this only happens when using BOTH the -O2 or higher (Os in my case) optimization flag AND -Wconversions. Both of which are in the Makefile included with Liberty v2.1 download from this site.

I ended up posting this as a bug to GNU's Bugzilla, and I got this response:
http://gcc.gnu.org/bugzilla/show_bug.cgi...
Quote
>-Wconversion
Will cause this warning.


sa.sin_port = (__extension__ ({ register unsigned short int __v, __x =
(siteinfo->port); if (__builtin_constant_p (__x)) __v = ((((__x) >> 8) & 0xff)
| (((__x) & 0xff) << 8)); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x)
: "cc"); __v; }));


__v = ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8));
is the part which is causing the warning. The issue is the (__x) >> 8 is
implictly casted into int.


In other words, its a problem with htons itself and not a darned thing I can do about it except turn off either -Wconversions or -Os

For now I turned off -Wconversions.
12 Jul, 2010, David Haley wrote in the 9th comment:
Votes: 0
Hmm, maybe this is why it worked for me:
$ g++ –version
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$


Oh well.
12 Jul, 2010, ralgith wrote in the 10th comment:
Votes: 0
hehehe, I'm waiting for the next version of my distro before I do upgrades at this point.
0.0/10