pointers and determining array size and weird code

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

 



  before i make a fool of myself on the main LKML, perhaps someone can
verify that some code is as strange as i think it is.

  from include/linux/netfilter/xt_sctp.h
...
#define ELEMCOUNT(x) (sizeof(x)/sizeof(x[0]))
...
#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap)                \
({                                                      \
        int i;                                          \
        int flag = 1;                                   \
        for (i = 0; i < ELEMCOUNT(chunkmap); i++) {     \
                if (chunkmap[i]) {                      \
                        flag = 0;                       \
                        break;                          \
                }                                       \
        }                                               \
        flag;                                           \
})
...

  so ELEMCOUNT() is clearly just an alternative to the more common
ARRAY_SIZE() macro.  but calling the macro SCTP_CHUNKMAP_IS_CLEAR()
pretty clearly assumes that you can determine the array size of the
macro parameter "chunkmap".  however, from the source file
net/netfilter/xt_sctp.c, we have:
...
static inline bool
match_packet(const struct sk_buff *skb,
             unsigned int offset,
             const u_int32_t *chunkmap,  <----- only a *pointer*
...
switch (chunk_match_type) {
        case SCTP_CHUNK_MATCH_ALL:
                return SCTP_CHUNKMAP_IS_CLEAR(chunkmap);
...

i don't see how you can reasonably call the macro
SCTP_CHUNKMAP_IS_CLEAR() with a *pointer* to an array and expect that
macro to be able to determine the "size" of that array.  AFAIK,
wouldn't you just get the answer "1" as the alleged size?

  or is it a bad idea that i've been up all night again?

rday

-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux