Skip to content

Commit 688bbb1

Browse files
committed
print_packet: fix wrong use of sizeof()
Coverity: CID 739690 (#1 of 1): Extra sizeof expression (SIZEOF_MISMATCH) Adding "4UL /* sizeof (haddr->v4) */" to pointer "haddr" of type "union olsr_ip_addr *" is suspicious because adding an integral value to this pointer automatically scales that value by the size, 16 bytes, of the pointed-to type, "union olsr_ip_addr". Most likely, "sizeof (haddr->v4)" is extraneous and should be replaced with 1. CID 739691 (#1 of 1): Extra sizeof expression (SIZEOF_MISMATCH) Adding "4UL /* sizeof (haddr->v4) */" to pointer "haddr" of type "union olsr_ip_addr *" is suspicious because adding an integral value to this pointer automatically scales that value by the size, 16 bytes, of the pointed-to type, "union olsr_ip_addr". Most likely, "sizeof (haddr->v4)" is extraneous and should be replaced with 1. Signed-off-by: Ferry Huberts <[email protected]>
1 parent da37af8 commit 688bbb1

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/print_packet.c

+16-14
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ print_messagedump(FILE * handle, uint8_t * msg, int16_t size)
164164
static void
165165
print_hellomsg(FILE * handle, uint8_t * data, int16_t totsize)
166166
{
167-
union olsr_ip_addr *haddr;
167+
uint8_t * haddr;
168168
int hellosize = totsize - ((olsr_cnf->ip_version == AF_INET) ? OLSR_MSGHDRSZ_IPV4 : OLSR_MSGHDRSZ_IPV6);
169169

170170
fprintf(handle, " +Htime: %u ms\n", me_to_reltime(data[2]));
@@ -184,10 +184,10 @@ print_hellomsg(FILE * handle, uint8_t * data, int16_t totsize)
184184
fprintf(handle, " ++ Link: %s, Status: %s, Size: %d\n", olsr_link_to_string(EXTRACT_LINK(hinf->link_code)),
185185
olsr_status_to_string(EXTRACT_STATUS(hinf->link_code)), ntohs(hinf->size));
186186

187-
for (haddr = (union olsr_ip_addr *)&hinf->neigh_addr; (char *)haddr < (char *)hinf + ntohs(hinf->size);
188-
haddr += sizeof(haddr->v4)) {
187+
for (haddr = (uint8_t *)&hinf->neigh_addr[0]; haddr < (uint8_t *)hinf + ntohs(hinf->size);
188+
haddr += sizeof(struct in_addr)) {
189189
struct ipaddr_str buf;
190-
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, haddr));
190+
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)ARM_NOWARN_ALIGN(haddr)));
191191
}
192192
}
193193

@@ -203,9 +203,10 @@ print_hellomsg(FILE * handle, uint8_t * data, int16_t totsize)
203203
fprintf(handle, " ++ Link: %s, Status: %s, Size: %d\n", olsr_link_to_string(EXTRACT_LINK(hinf6->link_code)),
204204
olsr_status_to_string(EXTRACT_STATUS(hinf6->link_code)), ntohs(hinf6->size));
205205

206-
for (haddr = (union olsr_ip_addr *)hinf6->neigh_addr; (char *)haddr < (char *)hinf6 + ntohs(hinf6->size); haddr++) {
206+
for (haddr = (uint8_t *)&hinf6->neigh_addr[0]; haddr < (uint8_t *)hinf6 + ntohs(hinf6->size);
207+
haddr += sizeof(struct in6_addr)) {
207208
struct ipaddr_str buf;
208-
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, haddr));
209+
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)ARM_NOWARN_ALIGN(haddr)));
209210
}
210211
}
211212

@@ -216,7 +217,7 @@ print_hellomsg(FILE * handle, uint8_t * data, int16_t totsize)
216217
static void
217218
print_hellomsg_lq(FILE * handle, uint8_t * data, int16_t totsize)
218219
{
219-
union olsr_ip_addr *haddr;
220+
uint8_t * haddr;
220221
int hellosize = totsize - ((olsr_cnf->ip_version == AF_INET) ? OLSR_MSGHDRSZ_IPV4 : OLSR_MSGHDRSZ_IPV6);
221222

222223
fprintf(handle, " +Htime: %u ms\n", me_to_reltime(data[2]));
@@ -236,11 +237,11 @@ print_hellomsg_lq(FILE * handle, uint8_t * data, int16_t totsize)
236237
fprintf(handle, " ++ Link: %s, Status: %s, Size: %d\n", olsr_link_to_string(EXTRACT_LINK(hinf->link_code)),
237238
olsr_status_to_string(EXTRACT_STATUS(hinf->link_code)), ntohs(hinf->size));
238239

239-
for (haddr = (union olsr_ip_addr *)&hinf->neigh_addr; (char *)haddr < (char *)hinf + ntohs(hinf->size);
240-
haddr += sizeof(haddr->v4)) {
240+
for (haddr = (uint8_t *)&hinf->neigh_addr[0]; haddr < (uint8_t *)hinf + ntohs(hinf->size);
241+
haddr += sizeof(struct in_addr) + active_lq_handler->hello_lqdata_size) {
241242
struct ipaddr_str buf;
242-
uint8_t *quality = (uint8_t *) haddr + olsr_cnf->ipsize;
243-
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, haddr));
243+
uint8_t *quality = haddr + olsr_cnf->ipsize;
244+
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)ARM_NOWARN_ALIGN(haddr)));
244245
fprintf(handle, " ++ LQ = %d, RLQ = %d\n", quality[0], quality[1]);
245246
}
246247
}
@@ -257,10 +258,11 @@ print_hellomsg_lq(FILE * handle, uint8_t * data, int16_t totsize)
257258
fprintf(handle, " ++ Link: %s, Status: %s, Size: %d\n", olsr_link_to_string(EXTRACT_LINK(hinf6->link_code)),
258259
olsr_status_to_string(EXTRACT_STATUS(hinf6->link_code)), ntohs(hinf6->size));
259260

260-
for (haddr = (union olsr_ip_addr *)hinf6->neigh_addr; (char *)haddr < (char *)hinf6 + ntohs(hinf6->size) + 4; haddr++) {
261+
for (haddr = (uint8_t *)&hinf6->neigh_addr[0]; haddr < (uint8_t *)hinf6 + ntohs(hinf6->size);
262+
haddr += sizeof(struct in6_addr) + active_lq_handler->hello_lqdata_size) {
261263
struct ipaddr_str buf;
262-
uint8_t *quality = (uint8_t *) haddr + olsr_cnf->ipsize;
263-
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, haddr));
264+
uint8_t *quality = haddr + olsr_cnf->ipsize;
265+
fprintf(handle, " ++ %s\n", olsr_ip_to_string(&buf, (union olsr_ip_addr *)ARM_NOWARN_ALIGN(haddr)));
264266
fprintf(handle, " ++ LQ = %d, RLQ = %d\n", quality[0], quality[1]);
265267
}
266268
}

0 commit comments

Comments
 (0)