On Thu, Jan 26, 2012 at 06:20:44PM +0100, Peter J. Philipp wrote:
> Hi,
>
> I have a vm that I upgraded to 5.1-beta last week some time. One of my
> software's is getting a compiler warning now that it didn't get in 5.0.
>
> ---
> cc -Wall -g -I/usr/local/include/db4 -c reply.c
> reply.c: In function 'create_anyreply':
> reply.c:2975: warning: array size (2) smaller than bound length (4)
> reply.c:2975: warning: array size (2) smaller than bound length (4)
> cc -Wall -g -I/usr/local/include/db4 -c additional.c
> ---
>
> The line of code looks like this:
>
> ---
> memcpy((char *)&answer->rdata, (char *)&sd->a[pos++ %
> mo
> d],
> sizeof(in_addr_t));
> ---
>
> The entire file can be found at sourceforge cvs repo here:
>
> http://wildcarddns.cvs.sourceforge.net/viewvc/wildcarddns/wildcarddnsd/reply.c?view=log
>
> What could cause this? And how do I fix my code to get rid of this warning?
>
> Thanks for any help,
>
> -peter
2553 struct answer {
2554 u_int16_t type; /* 0 */
2555 u_int16_t class; /* 2 */
2556 u_int32_t ttl; /* 4 */
2557 u_int16_t rdlength; /* 8 */
2558 char rdata[0]; /* 10 */
2559 } __packed;
Since rdate is an array, there's at least a redundant &.
Zero sized arrays are actually not legal and a gnu extension. With
ANDSI C, use [1] but note it changes the size of the struct), and with
C99 use [].
-Otto