Adding new gcc warnings
Julien ÉLIE
julien at trigofacile.com
Fri Dec 29 21:56:33 UTC 2017
Hi Russ,
> More than four years later, I finally took a look at these changes to the
> INN warning flags. :) I think most of these changes were already made in
> INN, but I also updated rra-c-util in places.
Thanks!
>> -Wdeclaration-after-statement can sometimes be useful for clarity (for
>> instance declaring a variable only in the loop it is used). I do not
>> know whether this warning should really be enforced.
>
> Yeah, this has now been adopted as standard C. The risk is that INN would
> fail to compile on older C compilers that follow the previous standard
> (although I think GCC has always supported this). I still avoid this
> coding style myself, but I'm happy for INN to adopt declaration at use.
Now adopted for INN.
Only 3 changes needed, so that's pretty fine. The risk of a build failure
on older C compilers seems limited.
--- frontends/inews.c (révision 10206)
+++ frontends/inews.c (copie de travail)
@@ -448,6 +448,9 @@
char *buff;
char *out;
char *p;
+#ifdef DO_MUNGE_GECOS
+ int left = SMBUF - 1;
+#endif
#if !defined(DONT_MUNGE_GETENV)
memset(outbuff, 0, SMBUF);
@@ -464,7 +467,6 @@
* buffer. Remember that on some Unix systems, the content of the GECOS
* field is under (untrusted) user control and we could be setgid. */
p = pwp->pw_gecos;
- int left = SMBUF - 1;
if (*p == '*')
p++;
for (out = outbuff; *p && !GECOSTERM(*p) && left; p++) {
--- frontends/rnews.c (révision 10206)
+++ frontends/rnews.c (copie de travail)
@@ -491,6 +491,7 @@
#if defined(DO_RNEWSPROGS)
char path[(SMBUF * 2) + 1];
char *p;
+ int len;
#endif /* defined(DO_RNEWSPROGS) */
char buff[SMBUF];
const char *cargv[4];
@@ -580,8 +581,6 @@
}
#if defined(DO_RNEWSPROGS)
- int len;
-
cargv[0] = UNPACK;
cargv[1] = NULL;
/* Ignore any possible leading pathnames, to avoid trouble. */
--- nnrpd/nnrpd.c (révision 10206)
+++ nnrpd/nnrpd.c (copie de travail)
@@ -370,6 +370,10 @@
void
CMDcapabilities(int ac, char *av[])
{
+#ifdef HAVE_SASL
+ const char *mechlist = NULL;
+#endif
+
if (ac == 2 && !IsValidKeyword(av[1])) {
Reply("%d Syntax error in keyword\r\n", NNTP_ERR_SYNTAX);
return;
@@ -382,8 +386,6 @@
Printf("IMPLEMENTATION %s\r\n", INN_VERSION_STRING);
#ifdef HAVE_SASL
- const char *mechlist = NULL;
-
/* Check for available SASL mechanisms.
* Start the string with a space for the strstr() calls afterwards. */
sasl_listmech(sasl_conn, NULL, " ", " ", "", &mechlist, NULL, NULL);
> Note that -Wdeclaration-after-statement only applies at block scope, so a
> variable declared at the top of a loop should be fine, since that's the
> first statement inside a new block.
Ah, OK, I misunderstood it 4 years ago :)
>> -Wredundant-decls is not used in INN because of noise generated by system
>> headers.
>
> I've now fixed this. The noise from the system headers were really our
> fault due to some old legacy compatibility code that's fairly pointless
> now.
Building INN with Perl or Python support, I encounter warnings like:
In file included from perl.c:26:0:
/usr/lib/x86_64-linux-gnu/perl/5.20/CORE/perl.h:1296:8: error: déclaration redondante de « strerror » [-Werror=redundant-decls]
char *strerror (int);
^~~~~~~~
In file included from ../include/clibrary.h:61:0,
from perl.c:19:
/usr/include/string.h:413:14: note: la déclaration précédente de « strerror » était ici
extern char *strerror (int __errnum) __THROW;
^~~~~~~~
/usr/lib/x86_64-linux-gnu/perl/5.20/CORE/perl.h:3862:8: error: déclaration redondante de « atof » [-Werror=redundant-decls]
double atof (const char*);
^~~~
In file included from /usr/include/features.h:374:0,
from /usr/include/inttypes.h:25,
from ../include/clibrary.h:51,
from perl.c:19:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: note: la définition précédente de « atof » était ici
__NTH (atof (const char *__nptr))
^
I've added a few pragmas like these ones, and it now builds fine:
+#pragma GCC diagnostic ignored "-Wredundant-decls"
#include <perl.h>
+#pragma GCC diagnostic warning "-Wredundant-decls"
+#pragma GCC diagnostic ignored "-Wredundant-decls"
#include "Python.h"
+#pragma GCC diagnostic warning "-Wredundant-decls"
> Added -Wmissing-declarations to rra-c-util. I haven't checked to see how
> many warnings would be generated in INN.
This warning flag is already enabled in INN.
> Added these to rra-c-util. -Wconversion -Wno-sign-conversion will
> probably require adding some cases; I had to make changes to both
> rra-c-util and C TAP Harness for those.
I'll see later for this one. I bet it will need some time to deal with.
--
Julien ÉLIE
« Nam et ipsa scientia potestas est. » (Francis Bacon)
More information about the inn-workers
mailing list