warning: array subscript is below array bounds

George Kirpichev _kirpichev_@mail.ru
Wed Jun 10 06:33:00 GMT 2009


Hi,

I would like to ask a question about array bounds checking feature in gcc.

My question is the following:

There is a code like:

    /* put message in buffer */
    (void) memcpy(sockFact_p->sockBuffer_p + sockFact_p->usedSize,
                  (char*)mqp_sp->msg.data - MSG_HEADER_LENGTH,
                  mqp_sp->msg.size + MSG_HEADER_LENGTH);

Where
mqp_sp->msg is
typedef struct MSGBUF_TAG
{
    W16 msgType_l;
    W16 receiver;
    W8  primitive;
    W8 remoteInstance;
    W16 size;
    int free;
    W16 poolId;
    W16 usedCounter;
    char   sendHead[MSG_HEADER_LENGTH];
    W8  data[MSG_MAX_DATALEN]; /* 4- or 8-octet alignment */
} MSGBUF_T;

Should the code snippet produce the warning:
warning: array subscript is below array bounds

And why if should?

>From my point of view type cast is more prioritized operation, thus
it should be ok. But seems, that gcc thinks in other way.

I've checked it with GCC 4.4.0 and warning has been emited.

What is you oppinion regarding that.

Should I create new BUG on GCC or something is wrong in our code?

BR/ Yury






More information about the Gcc-bugs mailing list