X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/5918c491c121b315104eaf1ae55f4512bb84fa1f..e5aebee6d80c8909048dc1ce865e9adb97d94fd7:/optimize.c diff --git a/optimize.c b/optimize.c index 0e5b5d61..da7a1e4b 100644 --- a/optimize.c +++ b/optimize.c @@ -21,8 +21,8 @@ * Optimization module for tcpdump intermediate representation. */ #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.74 2002-06-11 17:04:45 itojun Exp $ (LBL)"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.77 2003-11-15 23:24:00 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -1842,17 +1842,23 @@ opt_init(root) unMarkAll(); n = count_blocks(root); blocks = (struct block **)malloc(n * sizeof(*blocks)); + if (blocks == NULL) + bpf_error("malloc"); unMarkAll(); n_blocks = 0; number_blks_r(root); n_edges = 2 * n_blocks; edges = (struct edge **)malloc(n_edges * sizeof(*edges)); + if (edges == NULL) + bpf_error("malloc"); /* * The number of levels is bounded by the number of nodes. */ levels = (struct block **)malloc(n_blocks * sizeof(*levels)); + if (levels == NULL) + bpf_error("malloc"); edgewords = n_edges / (8 * sizeof(bpf_u_int32)) + 1; nodewords = n_blocks / (8 * sizeof(bpf_u_int32)) + 1; @@ -1860,6 +1866,8 @@ opt_init(root) /* XXX */ space = (bpf_u_int32 *)malloc(2 * n_blocks * nodewords * sizeof(*space) + n_edges * edgewords * sizeof(*space)); + if (space == NULL) + bpf_error("malloc"); p = space; all_dom_sets = p; for (i = 0; i < n; ++i) { @@ -1897,6 +1905,8 @@ opt_init(root) maxval = 3 * max_stmts; vmap = (struct vmapinfo *)malloc(maxval * sizeof(*vmap)); vnode_base = (struct valnode *)malloc(maxval * sizeof(*vnode_base)); + if (vmap == NULL || vnode_base == NULL) + bpf_error("malloc"); } /* @@ -1945,7 +1955,7 @@ convert_code_r(p) /* generate offset[] for convenience */ if (slen) { - offset = (struct slist **)calloc(sizeof(struct slist *), slen); + offset = (struct slist **)calloc(slen, sizeof(struct slist *)); if (!offset) { bpf_error("not enough core"); /*NOTREACHED*/ @@ -2093,6 +2103,8 @@ icode_to_fcode(root, lenp) n = *lenp = count_stmts(root); fp = (struct bpf_insn *)malloc(sizeof(*fp) * n); + if (fp == NULL) + bpf_error("malloc"); memset((char *)fp, 0, sizeof(*fp) * n); fstart = fp; ftail = fp + n;