]> The Tcpdump Group git mirrors - libpcap/commitdiff
compiler: squelch a warning from MSVC.
authorGuy Harris <[email protected]>
Fri, 21 Feb 2025 06:33:57 +0000 (22:33 -0800)
committerGuy Harris <[email protected]>
Fri, 21 Feb 2025 06:33:57 +0000 (22:33 -0800)
Cast the sum of SKF_AD_OFF and a metadata field offset to bpf_u_int32
before making it the k field of an instruction.  SKF_AD_OFF is negative,
as is the sum in question, so you have to cast it.

gencode.c

index 275cda2ec84c504b6b0a16e3d4d4f6b56326832d..d7318e030c423688fdc1ae6a5be22d27f554c264 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -9273,7 +9273,7 @@ gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid)
        unsigned cnt;
 
        s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
-       s->s.k = SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT;
+       s->s.k = (bpf_u_int32)(SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT);
 
        /* true -> next instructions, false -> beginning of b_vid */
        sjeq = new_stmt(cstate, JMP(BPF_JEQ));
@@ -9282,7 +9282,7 @@ gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid)
        sappend(s, sjeq);
 
        s2 = new_stmt(cstate, BPF_LD|BPF_H|BPF_ABS);
-       s2->s.k = SKF_AD_OFF + SKF_AD_VLAN_TAG;
+       s2->s.k = (bpf_u_int32)(SKF_AD_OFF + SKF_AD_VLAN_TAG);
        sappend(s, s2);
        sjeq->s.jt = s2;
 
@@ -9320,7 +9320,7 @@ gen_vlan_bpf_extensions(compiler_state_t *cstate, bpf_u_int32 vlan_num,
        /* generate new filter code based on extracting packet
         * metadata */
        s = new_stmt(cstate, BPF_LD|BPF_B|BPF_ABS);
-       s->s.k = SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT;
+       s->s.k = (bpf_u_int32)(SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT);
 
        b0 = new_block(cstate, JMP(BPF_JEQ));
        b0->stmts = s;