sa.sin_port = htons( siteinfo->port );
struct sockaddr_in sa;
unsigned short port; /* Port the server listens on */
sa.sin_port = htons( siteinfo->port );
$ 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.
$
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:
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:
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.