Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor clang warnings from freebsd #327

Closed
seanbruno opened this issue Oct 31, 2013 · 1 comment
Closed

Minor clang warnings from freebsd #327

seanbruno opened this issue Oct 31, 2013 · 1 comment

Comments

@seanbruno
Copy link

I found the following warnings from libpcap 1.4 (in base system of FreeBSD HEAD) and though they might be of interest to you guys:

/home/sbruno/bsd/head/lib/libpcap/../../contrib/libpcap/bpf_dump.c:60:18: warning: passing 'const struct bpf_insn *' to parameter of type 'struct bpf_insn *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                puts(bpf_image(insn, i));
                               ^~~~
/home/sbruno/bsd/head/lib/libpcap/../../contrib/libpcap/pcap.c:1690:22: warning: passing 'const struct bpf_insn *' to parameter of type 'struct bpf_insn *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                return (bpf_filter(fcode, pkt, h->len, h->caplen));
                                   ^~~~~
/home/sbruno/bsd/head/lib/libpcap/../../contrib/libpcap/pcap/pcap.h:412:35: note: passing argument to parameter here
u_int   bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); 

Index: contrib/libpcap/bpf_dump.c
===================================================================
--- contrib/libpcap/bpf_dump.c  (revision 257406)
+++ contrib/libpcap/bpf_dump.c  (working copy)
@@ -33,7 +33,7 @@
 void
 bpf_dump(struct bpf_program *p, int option)
 {
-   const struct bpf_insn *insn;
+   struct bpf_insn *insn;
    int i;
    int n = p->bf_len;

Index: contrib/libpcap/pcap.c
===================================================================
--- contrib/libpcap/pcap.c  (revision 257406)
+++ contrib/libpcap/pcap.c  (working copy)
@@ -1684,7 +1684,7 @@
 pcap_offline_filter(const struct bpf_program *fp, const struct pcap_pkthdr *h,
     const u_char *pkt)
 {
-   const struct bpf_insn *fcode = fp->bf_insns;
+   struct bpf_insn *fcode = fp->bf_insns;

    if (fcode != NULL) 
        return (bpf_filter(fcode, pkt, h->len, h->caplen));
@guyharris
Copy link
Member

Not of much interest to us, but it should be of interest to the FreeBSD folks, who should pick up - or fail to remove! this commit:

commit 0446821e49224c6a29be28760cc9c4cc14f56d8a
Author: guy <guy>
Date:   Wed Jan 2 04:16:46 2008 +0000

    Make some arguments const pointers if that makes sense.

    Add some additional checks to bpf_validate(), from OpenBSD.

    Use bpf_validate() in install_bpf_program(), so we validate programs
    even when they're being processed by userland filters; we make
    bpf_validate() not reject backward branches, as we use them for the
    protochain operator.

    For BPF, don't assume that, just because no_optimize was set, we have a
    program that we can't hand to the kernel; the user of the application
    might have specified no optimization (e.g., tcpdump with -O), or we
    might have generated code to handle 802.11 headers (the optimizer can't
    handle that code).  Instead, try handing the filter to the kernel and,
    if that fails, try it in userland.

    Get rid of BPF_MAXINSNS - we don't have a limit on program size in
    libpcap.

with an emphasis on the first line of the commit comment.

If I compare the 1.4.0 source from the tarball with the HEAD of FreeBSD's libpcap, I get:

bpf/net/bpf_filter.c:

212,213c212,213
<   register const struct bpf_insn *pc;
<   register const u_char *p;
---
>   register struct bpf_insn *pc;
>   register u_char *p;

bpf_dump.c:

34c34
< bpf_dump(const struct bpf_program *p, int option)
---
> bpf_dump(struct bpf_program *p, int option)

bpf_image.c:

56c56
<   const struct bpf_insn *p;
---
>   struct bpf_insn *p;

pcap/bpf.h:

1288c1288
< extern u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
---
> extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);

pcap/pcap.h:

414c412
< u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
---
> u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); 
417,418c415,416
< char  *bpf_image(const struct bpf_insn *, int);
< void  bpf_dump(const struct bpf_program *, int);
---
> char  *bpf_image(struct bpf_insn *, int);
> void  bpf_dump(struct bpf_program *, int);

Please make those differences go away (even if that means tweaking the kernel's net/bpf.h and net/bpf*.c; the rule in C should be "const unless it's required not to be const").

seanbruno added a commit to freebsd/freebsd-src that referenced this issue Oct 31, 2013
suggested by upstream

the-tcpdump-group/libpcap#327

Quiesce assignment warnings by use of const
dspinellis pushed a commit to dspinellis/unix-history-repo that referenced this issue Jul 29, 2014
suggested by upstream

the-tcpdump-group/libpcap#327

Quiesce assignment warnings by use of const


git-svn-id: svn+ssh://svn.freebsd.org/base/head@257466 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants