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

Boy this is basic C....

Just try out the code snippet

int i_arr[10];
char c_arr[30];
printf("chunk size(i_arr) = %d\n", sizeof(i_arr)/sizeof(i_arr[0]);
printf("chunk size (c_arr)= %d\n", sizeof(c_arr)/sizeof(c_arr[0]);

Guess you got the point..

And never go for a structure for such silly things Avishay , this is a
classic programming I say..:) Just enjoy the
beauty of this code piece and see how generic the code piece has been made.

Reply via email to