Re: Unused macro

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

 



Hello Florian,

On 4/4/21 10:05 PM, Florian Westphal wrote:
> Alejandro Colomar (man-pages) <alx.manpages@xxxxxxxxx> wrote:
>> I was updating the includes on some manual pages, when I found that a
>> macro used ARRAY_SIZE() without including a header that defines it.
>> That surprised me, because it would more than likely result in a compile
>> error, but of course, the macro wasn't being used:
>>
>> .../linux$ grep -rn SCTP_CHUNKMAP_IS_ALL_SET
>> include/uapi/linux/netfilter/xt_sctp.h:80:#define
>> SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \
>> .../linux$
> 
> This is an UAPI header, this macro is used by userspace software, e.g.
> iptables.
> 

Ahh, I see.  Thanks.

Then we still have the issue that ARRAY_SIZE is not defined in that
header (see a simple test below).  You should probably include some
header that provides it.

But again, if no one noticed this in more than a decade, either no one
used this macro, or they included other headers in the same file where
they used the macro.  So I'd still rethink if maybe that macro (and
possibly others) is really needed.

Test 1:

[[
$ cat test.c
#include <linux/netfilter/xt_sctp.h>

int foo(int x)
{
	int a[x];

	return ARRAY_SIZE(a);
}
$ cc -Wall -Wextra -Werror test.c -S -o test.s
test.c: In function ‘foo’:
test.c:7:9: error: implicit declaration of function ‘ARRAY_SIZE’
[-Werror=implicit-function-declaration]
    7 |  return ARRAY_SIZE(a);
      |         ^~~~~~~~~~
cc1: all warnings being treated as errors
$
]]

As you can see, no ARRAY_SIZE().

Test2:

[[
$ cat test.c
#include <linux/netfilter/xt_sctp.h>

int foo(int x)
{
	unsigned a[x];

	return SCTP_CHUNKMAP_IS_ALL_SET(a);
}
$ cc -Wall -Wextra -Werror test.c -S -o test.s
$ <test.s grep ARRAY_SIZE
	call	ARRAY_SIZE@PLT
$
]]

In this second test, tere's no error, because it's a system header, but
you can see that ARRAY_SIZE is treated as an implicitly declared
function, and it appears in the assembly file.

Cheers,

Alex



-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux