From f8e510aaefcb0c229ce72116c3b6902bf2e3da63 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Le Bail Date: Tue, 16 May 2023 15:21:11 +0200 Subject: struct pcap: Update buffer type from "void *" to "u_char *" This change should avoid these cppcheck warnings: pcap-hurd.c:77:18: warning: 'p->buffer' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer] pkt = p->buffer + offsetof(struct net_rcv_msg, packet) ^ pcap-hurd.c:78:8: warning: 'p->buffer+offsetof(struct net_rcv_msg,packet)' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer] + sizeof(struct packet_header) - ETH_HLEN; ^ pcap-hurd.c:79:25: warning: 'p->buffer' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer] memmove(pkt, p->buffer + offsetof(struct net_rcv_msg, header), ^ Remove some '(u_char *)' casts accordingly. --- sf-pcapng.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sf-pcapng.c') diff --git a/sf-pcapng.c b/sf-pcapng.c index 058a7244..cf87ac66 100644 --- a/sf-pcapng.c +++ b/sf-pcapng.c @@ -352,7 +352,7 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) * of the block. */ memcpy(p->buffer, &bhdr, sizeof(bhdr)); - bdata = (u_char *)p->buffer + sizeof(bhdr); + bdata = p->buffer + sizeof(bhdr); data_remaining = bhdr.total_length - sizeof(bhdr); if (read_bytes(fp, bdata, data_remaining, 1, errbuf) == -1) return (-1); @@ -943,12 +943,12 @@ pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision, * of the SHB. */ bhdrp = (struct block_header *)p->buffer; - shbp = (struct section_header_block *)((u_char *)p->buffer + sizeof(struct block_header)); + shbp = (struct section_header_block *)(p->buffer + sizeof(struct block_header)); bhdrp->block_type = magic_int; bhdrp->total_length = total_length; shbp->byte_order_magic = byte_order_magic; if (read_bytes(fp, - (u_char *)p->buffer + (sizeof(magic_int) + sizeof(total_length) + sizeof(byte_order_magic)), + p->buffer + (sizeof(magic_int) + sizeof(total_length) + sizeof(byte_order_magic)), total_length - (sizeof(magic_int) + sizeof(total_length) + sizeof(byte_order_magic)), 1, errbuf) == -1) goto fail; -- cgit v1.2.3