This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
warning: array subscript is below array bounds
- From: George Kirpichev <_kirpichev_ at mail dot ru>
- To: pinskia at gcc dot gnu dot org
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 10 Jun 2009 10:33:08 +0400
- Subject: warning: array subscript is below array bounds
- Reply-to: George Kirpichev <_kirpichev_ at mail dot ru>
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