]> The Tcpdump Group git mirrors - libpcap/blobdiff - optimize.c
On Linux, return error on interface going away, not just going down.
[libpcap] / optimize.c
index e676df9fe8227fae740c671075b8bd6da994a877..bcee9af4e07ca5a4d6dc357d80b0b767dbd7e3c3 100644 (file)
@@ -137,7 +137,7 @@ lowest_set_bit(int mask)
         * (It's currently not, in MSVC, even on 64-bit platforms, but....)
         */
        if (_BitScanForward(&bit, (unsigned int)mask) == 0)
-               return -1;      /* mask is zero */
+               abort();        /* mask is zero */
        return (int)bit;
 }
 #elif defined(MSDOS) && defined(__DJGPP__)
@@ -991,10 +991,10 @@ opt_peep(opt_state_t *opt_state, struct block *b)
         */
        if (b->s.code == (BPF_JMP|BPF_JEQ|BPF_K) &&
            !ATOMELEM(b->out_use, A_ATOM)) {
-               /*
-                * We can optimize away certain subtractions of the
-                * X register.
-                */
+               /*
+                * We can optimize away certain subtractions of the
+                * X register.
+                */
                if (last->s.code == (BPF_ALU|BPF_SUB|BPF_X)) {
                        val = b->val[X_ATOM];
                        if (opt_state->vmap[val].is_const) {
@@ -2069,7 +2069,7 @@ opt_error(opt_state_t *opt_state, const char *fmt, ...)
 
        if (opt_state->errbuf != NULL) {
                va_start(ap, fmt);
-               (void)pcap_vsnprintf(opt_state->errbuf,
+               (void)vsnprintf(opt_state->errbuf,
                    PCAP_ERRBUF_SIZE, fmt, ap);
                va_end(ap);
        }
@@ -2182,7 +2182,6 @@ opt_init(opt_state_t *opt_state, struct icode *ic)
        opt_state->n_edges = 2 * opt_state->n_blocks;
        opt_state->edges = (struct edge **)calloc(opt_state->n_edges, sizeof(*opt_state->edges));
        if (opt_state->edges == NULL) {
-               free(opt_state->blocks);
                opt_error(opt_state, "malloc");
        }
 
@@ -2191,8 +2190,6 @@ opt_init(opt_state_t *opt_state, struct icode *ic)
         */
        opt_state->levels = (struct block **)calloc(opt_state->n_blocks, sizeof(*opt_state->levels));
        if (opt_state->levels == NULL) {
-               free(opt_state->edges);
-               free(opt_state->blocks);
                opt_error(opt_state, "malloc");
        }
 
@@ -2203,9 +2200,6 @@ opt_init(opt_state_t *opt_state, struct icode *ic)
        opt_state->space = (bpf_u_int32 *)malloc(2 * opt_state->n_blocks * opt_state->nodewords * sizeof(*opt_state->space)
                                 + opt_state->n_edges * opt_state->edgewords * sizeof(*opt_state->space));
        if (opt_state->space == NULL) {
-               free(opt_state->levels);
-               free(opt_state->edges);
-               free(opt_state->blocks);
                opt_error(opt_state, "malloc");
        }
        p = opt_state->space;
@@ -2245,19 +2239,10 @@ opt_init(opt_state_t *opt_state, struct icode *ic)
        opt_state->maxval = 3 * max_stmts;
        opt_state->vmap = (struct vmapinfo *)calloc(opt_state->maxval, sizeof(*opt_state->vmap));
        if (opt_state->vmap == NULL) {
-               free(opt_state->space);
-               free(opt_state->levels);
-               free(opt_state->edges);
-               free(opt_state->blocks);
                opt_error(opt_state, "malloc");
        }
        opt_state->vnode_base = (struct valnode *)calloc(opt_state->maxval, sizeof(*opt_state->vnode_base));
        if (opt_state->vnode_base == NULL) {
-               free(opt_state->vmap);
-               free(opt_state->space);
-               free(opt_state->levels);
-               free(opt_state->edges);
-               free(opt_state->blocks);
                opt_error(opt_state, "malloc");
        }
 }
@@ -2416,7 +2401,7 @@ filled:
                if (off >= 256) {
                    /* offset too large for branch, must add a jump */
                    if (p->longjt == 0) {
-                       /* mark this instruction and retry */
+                       /* mark this instruction and retry */
                        p->longjt++;
                        return(0);
                    }
@@ -2436,7 +2421,7 @@ filled:
                if (off >= 256) {
                    /* offset too large for branch, must add a jump */
                    if (p->longjf == 0) {
-                       /* mark this instruction and retry */
+                       /* mark this instruction and retry */
                        p->longjf++;
                        return(0);
                    }
@@ -2477,7 +2462,7 @@ filled:
  * done with the filter program.  See the pcap man page.
  */
 struct bpf_insn *
-icode_to_fcode(struct icode *ic, struct block *root, u_int *lenp, 
+icode_to_fcode(struct icode *ic, struct block *root, u_int *lenp,
     char *errbuf)
 {
        u_int n;
@@ -2501,7 +2486,7 @@ icode_to_fcode(struct icode *ic, struct block *root, u_int *lenp,
 
            fp = (struct bpf_insn *)malloc(sizeof(*fp) * n);
            if (fp == NULL) {
-               (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
+               (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
                    "malloc");
                free(fp);
                return NULL;
@@ -2528,7 +2513,7 @@ conv_error(conv_state_t *conv_state, const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       (void)pcap_vsnprintf(conv_state->errbuf,
+       (void)vsnprintf(conv_state->errbuf,
            PCAP_ERRBUF_SIZE, fmt, ap);
        va_end(ap);
        longjmp(conv_state->top_ctx, 1);
@@ -2552,7 +2537,7 @@ install_bpf_program(pcap_t *p, struct bpf_program *fp)
         * Validate the program.
         */
        if (!pcap_validate_filter(fp->bf_insns, fp->bf_len)) {
-               pcap_snprintf(p->errbuf, sizeof(p->errbuf),
+               snprintf(p->errbuf, sizeof(p->errbuf),
                        "BPF program is not valid");
                return (-1);
        }
@@ -2641,7 +2626,7 @@ dot_dump_edge(struct icode *ic, struct block *block, FILE *out)
        "block1":sw -> "block3":n [label="F"];
     }
  *
- *  After install graphviz on http://www.graphviz.org/, save it as bpf.dot
+ *  After install graphviz on https://www.graphviz.org/, save it as bpf.dot
  *  and run `dot -Tpng -O bpf.dot' to draw the graph.
  */
 static int