screen-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[screen-devel] suppress GCC 10 warnings


From: Christophe Meyering
Subject: [screen-devel] suppress GCC 10 warnings
Date: Sat, 1 Feb 2020 13:53:29 -0800

Hello,

Using GCC10 on Fedora 31, I built screen from a git clone of the latest sources.
After running
$cd src && ./autogen.sh && ./configure && make
I got multiple warnings in acls.c:

acls.c: In function ‘GrowBitfield’:
acls.h:44:35: warning: dereferencing ‘void *’ pointer
   44 | #define ACLBYTE(data, w)   ((data)[(w) >> 3])
      |                                   ^
acls.c:95:49: note: in expansion of macro ‘ACLBYTE’
   95 |  if (!(n = (AclBits) calloc(1, (unsigned long)(&ACLBYTE(NULL, len + delta + 1)))))
      |                                                 ^~~~~~~
acls.c: In function ‘DoSu’:
acls.c:400:6: warning: unused variable ‘sorry’ [-Wunused-variable]
  400 |  int sorry = 0;
      |      ^~~~~
acls.c:399:18: warning: unused variable ‘u’ [-Wunused-variable]
  399 |  struct acluser *u;
      |                  ^
acls.c:397:29: warning: unused parameter ‘up’ [-Wunused-parameter]
  397 | char *DoSu(struct acluser **up, char *name, char *pw1, char *pw2)
      |            ~~~~~~~~~~~~~~~~~^~
acls.c:397:39: warning: unused parameter ‘name’ [-Wunused-parameter]
  397 | char *DoSu(struct acluser **up, char *name, char *pw1, char *pw2)
      |                                 ~~~~~~^~~~
acls.c:397:51: warning: unused parameter ‘pw1’ [-Wunused-parameter]
  397 | char *DoSu(struct acluser **up, char *name, char *pw1, char *pw2)
      |                                             ~~~~~~^~~
acls.c:397:62: warning: unused parameter ‘pw2’ [-Wunused-parameter]
  397 | char *DoSu(struct acluser **up, char *name, char *pw1, char *pw2)
      |                                                        ~~~~~~^~~

In order to suppress the warning for GrowBitfield, I cast NULL as a char * (patch 0001).
In order to suppress DoSu's unused-variable warnings, I moved the two variable declarations into the #if-0'd block (patch 0002).
In order to suppress DoSu's unused-parameter warnings, I marked the four parameters (patch 0005).

I then ran $make check and got a couple more warnings:

In file included from tests/test-winmsgbuf.c:24:
tests/test-winmsgbuf.c:45:17: warning: initialization of ‘char * (*)(WinMsgBufContext *, WinMsgBuf *)’ from incompatible pointer type ‘const char * (*)(WinMsgBufContext *, WinMsgBuf *)’ [-Wincompatible-pointer-types]
   45 | SIGNATURE_CHECK(wmbc_mergewmb, char *, (WinMsgBufContext *, WinMsgBuf *));
      |                 ^~~~~~~~~~~~~
tests/signature.h:46:71: note: in definition of macro ‘SIGNATURE_CHECK2’
   46 |   static ret (* __attribute__((unused)) signature_check ## id) args = fn
      |                                                                       ^~
tests/signature.h:39:3: note: in expansion of macro ‘SIGNATURE_CHECK1’
   39 |   SIGNATURE_CHECK1 (fn, ret, args, __LINE__)
      |   ^~~~~~~~~~~~~~~~
tests/test-winmsgbuf.c:45:1: note: in expansion of macro ‘SIGNATURE_CHECK’
   45 | SIGNATURE_CHECK(wmbc_mergewmb, char *, (WinMsgBufContext *, WinMsgBuf *));
      | ^~~~~~~~~~~~~~~
tests/test-winmsgbuf.c: In function ‘main’:
tests/test-winmsgbuf.c:298:19: warning: implicit declaration of function ‘alloca’; did you mean ‘calloc’? [-Wimplicit-function-declaration]
  298 |   char *expect2 = alloca(strlen(expect) + szadd + 1);
      |                   ^~~~~~
      |                   calloc

I fixed the incompatible-pointer-type warning by adding const to the macro on line 45 in test-winmsgbuf (patch 0003).
Finally, I replaced the alloca call to a malloc/free pair to fix the implicit-funtion-declaration warning (patch 0004).
Another option would be to #include <alloca.h>

Chris Meyering

Attachment: 0001-build-cast-NULL-to-char-to-prevent-GCC-10-warning.patch
Description: Text Data

Attachment: 0003-build-test-winmsgbuf.c-add-const-to-avoid-GCC-10-war.patch
Description: Text Data

Attachment: 0004-build-tests-test-winmsgbuf.c-avoid-GCC-10-alloca-war.patch
Description: Text Data

Attachment: 0005-build-acls.c-mark-unused-parameters.patch
Description: Text Data

Attachment: 0002-cleanup-acls.c-move-unused-variables-into-if-0-block.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]