1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-03 19:23:13 +02:00

Enable additional compiler warnings. Update code to conform to these

new standards, possible to compile with -Werror with them.
This commit is contained in:
Bram Matthys
2019-03-27 09:03:30 +01:00
parent 5a38d8ed75
commit dd2af3b31c
14 changed files with 1765 additions and 658 deletions
Vendored
+1686 -573
View File
File diff suppressed because it is too large Load Diff
+62 -73
View File
@@ -45,79 +45,6 @@ AC_DEFINE_UNQUOTED([UNREAL_VERSION_MINOR], [$UNREAL_VERSION_MINOR], [Minor versi
UNREAL_VERSION_SUFFIX=["-dev"]
AC_DEFINE_UNQUOTED([UNREAL_VERSION_SUFFIX], ["$UNREAL_VERSION_SUFFIX"], [Version suffix such as a beta marker or release candidate marker. (e.g.: -rcX for unrealircd-3.2.9-rcX)])
AC_PROG_CC
if test "$ac_cv_prog_gcc" = "yes"; then
CFLAGS="$CFLAGS -funsigned-char"
AC_CACHE_CHECK(if gcc has a working -pipe, ac_cv_pipe, [
save_cflags="$CFLAGS"
CFLAGS="$CFLAGS -pipe"
AC_TRY_COMPILE(,, ac_cv_pipe="yes", ac_cv_pipe="no")
CFLAGS="$save_cflags"
])
if test "$ac_cv_pipe" = "yes"; then
CFLAGS="-pipe $CFLAGS"
fi
fi
dnl UnrealIRCd might not be strict-aliasing safe at this time
AC_CACHE_CHECK(if the compiler has a working -fno-strict-aliasing, ac_cv_nsa, [
save_cflags="$CFLAGS"
CFLAGS="$CFLAGS -fno-strict-aliasing"
AC_TRY_COMPILE(,, ac_cv_nsa="yes", ac_cv_nsa="no")
CFLAGS="$save_cflags"
])
if test "$ac_cv_nsa" = "yes"; then
CFLAGS="$CFLAGS -fno-strict-aliasing"
fi
dnl Pointer signedness warnings are really a pain and 99.9% of the time
dnl they are of absolutely no use whatsoever. IMO the person who decided
dnl to enable this without -Wall should be shot on sight.
AC_CACHE_CHECK(if the compiler has a working -Wno-pointer-sign, ac_cv_nps, [
save_cflags="$CFLAGS"
CFLAGS="$CFLAGS -Wno-pointer-sign"
AC_TRY_COMPILE(,, ac_cv_nps="yes", ac_cv_nps="no")
CFLAGS="$save_cflags"
])
if test "$ac_cv_nps" = "yes"; then
CFLAGS="$CFLAGS -Wno-pointer-sign"
fi
dnl This is purely for charsys.c... I like it so we can easily read
dnl this for non-utf8. We can remove it once we ditch non-utf8 some day
dnl of course, or decide to ignore me and encode them.
AC_CACHE_CHECK(if the compiler has a working -Wno-invalid-source-encoding, ac_cv_nise, [
save_cflags="$CFLAGS"
CFLAGS="$CFLAGS -Wno-invalid-source-encoding"
AC_TRY_COMPILE(,, ac_cv_nise="yes", ac_cv_nise="no")
CFLAGS="$save_cflags"
])
if test "$ac_cv_nise" = "yes"; then
CFLAGS="$CFLAGS -Wno-invalid-source-encoding"
fi
dnl Pffff..
AC_CACHE_CHECK(if the compiler has a working -Wno-format-zero-length, ac_cv_nfzl, [
save_cflags="$CFLAGS"
CFLAGS="$CFLAGS -Wno-format-zero-length"
AC_TRY_COMPILE(,, ac_cv_nfzl="yes", ac_cv_nfzl="no")
CFLAGS="$save_cflags"
])
if test "$ac_cv_nfzl" = "yes"; then
CFLAGS="$CFLAGS -Wno-format-zero-length"
fi
dnl More and more and more....
AC_CACHE_CHECK(if the compiler has a working -Wno-format-truncation, ac_cv_nft, [
save_cflags="$CFLAGS"
CFLAGS="$CFLAGS -Wno-format-truncation -Werror"
AC_TRY_COMPILE(,, ac_cv_nft="yes", ac_cv_nft="no")
CFLAGS="$save_cflags"
])
if test "$ac_cv_nft" = "yes"; then
CFLAGS="$CFLAGS -Wno-format-truncation"
fi
AC_PATH_PROG(RM,rm)
AC_PATH_PROG(CP,cp)
AC_PATH_PROG(TOUCH,touch)
@@ -224,6 +151,68 @@ CXX="$saved_CXX"
LD="$saved_LD"
dnl HARDENING END
dnl UnrealIRCd might not be strict-aliasing safe at this time
check_cc_cxx_flag([-fno-strict-aliasing], [CFLAGS="$CFLAGS -fno-strict-aliasing"])
dnl Previously -funsigned-char was in a config check. It would always
dnl be enabled with gcc and clang. We now unconditionally enable it,
dnl skipping the check. This will cause an error if someone uses a
dnl non-gcc/non-clang compiler that does not support -funsigned-char
dnl which is good. After all, we really depend on it.
dnl UnrealIRCd should never be compiled without char being unsigned.
CFLAGS="$CFLAGS -funsigned-char"
dnl Compiler -W checks...
dnl We should be able to turn this on unconditionally:
CFLAGS="$CFLAGS -Wall"
dnl More warnings (if the compiler supports it):
check_cc_cxx_flag([-Wextra], [CFLAGS="$CFLAGS -Wextra"])
check_cc_cxx_flag([-Waggregate-return], [CFLAGS="$CFLAGS -Waggregate-return"])
dnl The following few are more experimental, if they have false positives we'll have
dnl to disable them:
dnl Can't use this, too bad: check_cc_cxx_flag([-Wlogical-op], [CFLAGS="$CFLAGS -Wlogical-op"])
check_cc_cxx_flag([-Wduplicated-cond], [CFLAGS="$CFLAGS -Wduplicated-cond"])
check_cc_cxx_flag([-Wduplicated-branches], [CFLAGS="$CFLAGS -Wduplicated-branches"])
dnl And now to filter out certain warnings:
dnl Pointer signedness warnings are really a pain and 99.9% of the time
dnl they are of absolutely no use whatsoever. IMO the person who decided
dnl to enable this without -Wall should be shot on sight.
check_cc_cxx_flag([-Wno-pointer-sign], [CFLAGS="$CFLAGS -Wno-pointer-sign"])
dnl This is purely for charsys.c... I like it so we can easily read
dnl this for non-utf8. We can remove it once we ditch non-utf8 some day
dnl of course, or decide to ignore me and encode them.
check_cc_cxx_flag([-Wno-invalid-source-encoding], [CFLAGS="$CFLAGS -Wno-invalid-source-encoding"])
check_cc_cxx_flag([-Wno-format-zero-length], [CFLAGS="$CFLAGS -Wno-format-zero-length"])
check_cc_cxx_flag([-Wno-format-truncation], [CFLAGS="$CFLAGS -Wno-format-truncation"])
dnl While it can be useful to occasionally to compile with warnings about
dnl unused variables and parameters, we often 'think ahead' when coding things
dnl so they may be useless now but not later. Similarly, for variables, we
dnl don't always care about a variable that may still be present in a build
dnl without DEBUGMODE. Unused variables are optimized out anyway.
check_cc_cxx_flag([-Wno-unused], [CFLAGS="$CFLAGS -Wno-unused"])
check_cc_cxx_flag([-Wno-unused-parameter], [CFLAGS="$CFLAGS -Wno-unused-parameter"])
dnl We use this and this warning is meaningless since 'char' is always unsigned
dnl in UnrealIRCd compiles (-funsigned-char).
check_cc_cxx_flag([-Wno-char-subscripts], [CFLAGS="$CFLAGS -Wno-char-subscripts"])
check_cc_cxx_flag([-Wno-sign-compare], [CFLAGS="$CFLAGS -Wno-sign-compare"])
dnl This one fails with ircstrdup(var, staticstring)
dnl Shame we have to turn it off completely...
check_cc_cxx_flag([-Wno-address], [CFLAGS="$CFLAGS -Wno-address"])
dnl End of -W... compiler checks.
dnl module checking based on Hyb7's module checking code
AC_DEFUN([AC_ENABLE_DYN],
[
+1 -1
View File
@@ -80,7 +80,7 @@ aCtab cFlagTab[] = {
{MODE_BAN, 'b', 1, 1},
{MODE_EXCEPT, 'e', 1, 1}, /* exception ban */
{MODE_INVEX, 'I', 1, 1}, /* invite-only exception */
{0x0, 0x0, 0x0}
{0x0, 0x0, 0x0, 0x0}
};
char cmodestring[512];
+1 -1
View File
@@ -169,7 +169,7 @@ int dbuf_getmsg(dbuf *dyn, char *buf)
}
else switch (phase)
{
case 0: phase = 1;
case 0: phase = 1; /* FALLTHROUGH */
case 1: if (line_bytes++ < BUFSIZE - 2)
*buf++ = c;
break;
+1 -1
View File
@@ -502,7 +502,7 @@ invalidsyntax:
return EX_DENY;
}
/* falltrough -- should not be used */
/* fallthrough -- should not be used */
return EX_DENY;
}
+1 -1
View File
@@ -107,7 +107,7 @@ int cmodeL_is_ok(aClient *sptr, aChannel *chptr, char mode, char *para, int type
return EX_ALLOW;
}
/* falltrough -- should not be used */
/* fallthrough -- should not be used */
return EX_DENY;
}
+1
View File
@@ -32,6 +32,7 @@ ModuleHeader MOD_HEADER(m_chghost)
"4.2", /* Version */
"/chghost", /* Short description of module */
"3.2-b8-1",
NULL
};
MOD_INIT(m_chghost)
+4 -1
View File
@@ -821,6 +821,7 @@ int do_mode_char(aChannel *chptr, long modetype, char modechar, char *param,
if (!is_halfop(cptr, chptr)) /* htrig will take care of halfop override notices */
opermode = 1;
}
goto process_listmode;
case MODE_CHANPROT:
REQUIRE_PARAMETER()
/* not uline, not server, not chanowner, not an samode, not -a'ing yourself... */
@@ -835,12 +836,13 @@ int do_mode_char(aChannel *chptr, long modetype, char modechar, char *param,
if (!is_halfop(cptr, chptr)) /* htrig will take care of halfop override notices */
opermode = 1;
}
goto process_listmode;
case MODE_HALFOP:
case MODE_CHANOP:
case MODE_VOICE:
REQUIRE_PARAMETER()
process_listmode:
if (!(who = find_chasing(cptr, param, &chasing)))
break;
if (!who->user)
@@ -1656,6 +1658,7 @@ CMD_FUNC(_m_umode)
set_snomask(sptr, parv[3]);
goto def;
}
break;
case 'o':
case 'O':
if(sptr->from->flags & FLAGS_QUARANTINE)
+1 -1
View File
@@ -3052,7 +3052,7 @@ static int comp_with_mask(void *addr, void *dest, u_int mask)
if (memcmp(addr, dest, mask / 8) == 0)
{
int n = mask / 8;
int m = ((-1) << (8 - (mask % 8)));
int m = (0xffff << (8 - (mask % 8)));
if (mask % 8 == 0 || (((u_char *) addr)[n] & m) == (((u_char *) dest)[n] & m))
{
return (1);
+1 -1
View File
@@ -474,7 +474,7 @@ int webirc_local_pass(aClient *sptr, char *password)
return dowebirc(sptr, ip, host, NULL);
}
/* falltrough if not in webirc block.. */
/* fallthrough if not in webirc block.. */
}
return 0; /* not webirc */
+3 -3
View File
@@ -69,7 +69,7 @@ aClient *find_client(char *name, aClient *cptr)
return hash_find_client(name, NULL);
}
aClient inline *find_nickserv(char *name, aClient *cptr)
aClient *find_nickserv(char *name, aClient *cptr)
{
if (name)
cptr = hash_find_nickserver(name, cptr);
@@ -91,7 +91,7 @@ aClient inline *find_nickserv(char *name, aClient *cptr)
** the old. 'name' is now assumed to be a null terminated
** string.
*/
aClient inline *find_server(char *name, aClient *cptr)
aClient *find_server(char *name, aClient *cptr)
{
if (name)
{
@@ -105,7 +105,7 @@ aClient inline *find_server(char *name, aClient *cptr)
}
aClient inline *find_name(char *name, aClient *cptr)
aClient *find_name(char *name, aClient *cptr)
{
aClient *c2ptr = cptr;
+1 -1
View File
@@ -1341,7 +1341,7 @@ void read_packet(int fd, int revents, void *data)
if (length <= 0)
{
if (length < 0 && (ERRNO == P_EWOULDBLOCK || ERRNO == P_EAGAIN || ERRNO == P_EINTR))
if (length < 0 && ((ERRNO == P_EWOULDBLOCK) || (ERRNO == P_EAGAIN) || (ERRNO == P_EINTR)))
return;
if (IsServer(cptr) || cptr->serv) /* server or outgoing connection */
+1 -1
View File
@@ -114,7 +114,7 @@ SpamfilterTargetTable spamfiltertargettable[] = {
{ SPAMF_USER, 'u', "user", "NICK" },
{ SPAMF_AWAY, 'a', "away", "AWAY" },
{ SPAMF_TOPIC, 't', "topic", "TOPIC" },
{ 0, 0, 0 }
{ 0, 0, 0, 0 }
};
+1
View File
@@ -92,6 +92,7 @@ int deliver_it(aClient *cptr, char *str, int len, int *want_read)
case SSL_ERROR_SSL:
if (ERRNO == P_EAGAIN)
break;
/* FALLTHROUGH */
default:
return -1; /* hm.. why was this 0?? we have an error! */
}