On 26 January 2012 15:20, Peter J. Philipp <[email protected]> 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
>
You forgot the definition of answer{}
struct answer {
char name[2];
u_int16_t type;
u_int16_t class;
u_int32_t ttl;
u_int16_t rdlength; /* 12 */
char rdata; /* 12 + 16 */
} __attribute__((packed));
The thing is that GCC knows rdata is 1 byte long, you're doing the
magic here if I'm correct:
/* skip dns header, question name, qtype and qclass */
answer = (struct answer *)(&reply[0] + sizeof(struct dns_header) +
q->hdr->namelen + 4);
You can remove the __attribute__((packed)) and turn rdata into "char
rdata[]".
Or just get a pointer past sizeof(answer).