]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge topic branch t/overflow into master
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 3 Oct 2022 15:59:56 +0000 (17:59 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 3 Oct 2022 16:01:20 +0000 (18:01 +0200)
This series implements a new memory allocation API which checks
for overflows. The first part of the series just renames the main
allocation functions. Later patches in the series implement allocators
which take two size_t arguments (like calloc(3)) and check whether the
multiplication overflows by employing the __builtin_mul_overflow()
primitive supported by gcc and clang. This requires us to bump the
lowest supported gcc and clang version.

* refs/heads/t/overflow:
  build: Compile with -ftrapv.
  string: Introduce arr_zalloc().
  string: Introduce arr_alloc().
  string: Introduce arr_realloc() and check for integer overflow.
  string: Rename para_calloc() -> zalloc().
  string: Rename para_malloc() -> alloc().
  string: Overhaul para_strdup().

83 files changed:
Makefile.real
NEWS.md
aac_afh.c
aacdec_filter.c
acl.c
afh_recv.c
afs.c
aft.c
alsa_mix.c
alsa_write.c
amp_filter.c
ao_write.c
audioc.c
audiod.c
audiod_command.c
base64.c
bitstream.c
blob.c
buffer_tree.c
check_wav.c
chunk_queue.c
client.c
client_common.c
close_on_fork.c
command.c
compress_filter.c
crypt_common.c
dccp_recv.c
dccp_send.c
fd.c
fec.c
fecdec_filter.c
file_write.c
filter.c
flac_afh.c
flacdec_filter.c
gcrypt.c
grab_client.c
gui.c
http_recv.c
http_send.c
imdct.c
interactive.c
mood.c
mp.c
mp3_afh.c
mp3dec_filter.c
mp4.c
net.c
ogg_afh_common.c
oggdec_filter.c
openssl.c
opus_afh.c
opusdec_filter.c
oss_mix.c
oss_write.c
para.h
play.c
prebuffer_filter.c
recv_common.c
resample_filter.c
ringbuffer.c
sched.c
score.c
send_common.c
server.c
sideband.c
signal.c
spx_afh.c
spxdec_filter.c
string.c
string.h
sync_filter.c
udp_send.c
user_list.c
vss.c
wav_filter.c
web/manual.md
wma_afh.c
wmadec_filter.c
write.c
write_common.c
yy/mp.y

index 92ef995249680fabdbcdaa1b257b92fabdfd5d2a..4dac79f9941f5cee0c2848b53e0312b1233a385d 100644 (file)
@@ -121,6 +121,7 @@ CPPFLAGS += -I$(yy_build_dir)
 CPPFLAGS += $(lopsub_cppflags)
 
 STRICT_CFLAGS += -fno-strict-aliasing
+STRICT_CFLAGS += -ftrapv
 STRICT_CFLAGS += -g
 STRICT_CFLAGS += -Os
 STRICT_CFLAGS += -Wundef -W -Wuninitialized
diff --git a/NEWS.md b/NEWS.md
index e5b9901054062c92667c3ab403daa5960dd90603..a6af789b852b61c56e8122797d708018a7572bf3 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -15,6 +15,9 @@ NEWS
   new ll command. It is available for para_server and para_audiod.
 - All calls to select(2) have been replaced by calls to poll(2)
   to avoid known shortcomings of the select API.
+- All allocation functions now check for integer overflow. Since this
+  requires support from the compiler, the oldest supported gcc version
+  has been bumped to gcc-5.4 (released in 2015).
 
 [tarball](./releases/paraslash-git.tar.xz)
 
index 79fa30ddc2f794f5c586c28b2823c7fce26dd9b8..c4301a2f178257b19d56b3cf297da3e1eaff337c 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -59,7 +59,7 @@ static off_t aac_afh_seek_cb(void *user_data, off_t offset, int whence)
 static int aac_afh_open(const void *map, size_t mapsize, void **afh_context)
 {
        int ret;
-       struct aac_afh_context *c = para_malloc(sizeof(*c));
+       struct aac_afh_context *c = alloc(sizeof(*c));
 
        c->map = map;
        c->mapsize = mapsize;
index 36a783c5ecf6ae4538a55fb8c61669707bd4a9b6..87a7900af3ee9b43e1a661d66cdd54d1625b0952 100644 (file)
@@ -52,7 +52,7 @@ static int aacdec_execute(struct btr_node *btrn, const char *cmd, char **result)
 static void aacdec_open(struct filter_node *fn)
 {
        NeAACDecConfigurationPtr c;
-       struct private_aacdec_data *padd = para_calloc(sizeof(*padd));
+       struct private_aacdec_data *padd = zalloc(sizeof(*padd));
 
        padd->handle = NeAACDecOpen();
        c = NeAACDecGetCurrentConfiguration(padd->handle);
@@ -136,7 +136,7 @@ next_buffer:
        consumed += frame_info.bytesconsumed;
        if (!frame_info.samples)
                goto success;
-       btrbuf = para_malloc(2 * frame_info.samples);
+       btrbuf = arr_alloc(2, frame_info.samples);
        for (i = 0; i < frame_info.samples; i++) {
                short sh = ((short *)outbuf)[i];
                write_int16_host_endian(btrbuf + loaded, sh);
diff --git a/acl.c b/acl.c
index 59ffab3e0a188a8ac921555b83a9276907ecfa46..ddf93ecc6e083299daf7a573b0adce16c3b4051f 100644 (file)
--- a/acl.c
+++ b/acl.c
@@ -81,7 +81,7 @@ no_match:
  */
 void acl_add_entry(struct list_head *acl, char *addr, int netmask)
 {
-       struct access_info *ai = para_malloc(sizeof(struct access_info));
+       struct access_info *ai = alloc(sizeof(struct access_info));
 
        inet_pton(AF_INET, addr, &ai->addr);
        ai->netmask = netmask;
index 889fdce821f4b9aec85c1b01976e4fae6e05e176..eebac67f9c80a270cd91337190ed9ad1eb569898 100644 (file)
@@ -75,7 +75,7 @@ static int afh_recv_open(struct receiver_node *rn)
 
        if (!fn || *fn == '\0')
                return -E_AFH_RECV_BAD_FILENAME;
-       rn->private_data = pard = para_calloc(sizeof(*pard));
+       rn->private_data = pard = zalloc(sizeof(*pard));
        afhi = &pard->afhi;
        ret = mmap_full_file(fn, O_RDONLY, &pard->map,
                &pard->map_size, &pard->fd);
@@ -188,7 +188,7 @@ static int afh_recv_post_monitor(__a_unused struct sched *s, void *context)
                        pard->map_size, &header, &size);
                if (size > 0) {
                        PARA_INFO_LOG("writing header (%zu bytes)\n", size);
-                       buf = para_malloc(size);
+                       buf = alloc(size);
                        memcpy(buf, header, size);
                        btr_add_output(buf, size, btrn);
                        afh_free_header(header, pard->audio_format_num);
diff --git a/afs.c b/afs.c
index f29080290424d95506ec643df567e24c2d095a74..3da39f324b83b2a6d83d1f468732f74cc4313ae2 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -960,7 +960,7 @@ static int command_post_monitor(struct sched *s, void *context)
                close(fd);
                return 0;
        }
-       client = para_malloc(sizeof(*client));
+       client = alloc(sizeof(*client));
        client->fd = fd;
        client->connect_time = *now;
        para_list_add(&client->node, &afs_client_list);
diff --git a/aft.c b/aft.c
index e0bde7fc78c8365f33aa8e5aae9f751a3dabb751..f690e81951b4c7911c2f726b36fee9a673badce7 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -412,7 +412,7 @@ static void load_chunk_table(struct afh_info *afhi, const struct osl_object *ct)
                return;
        }
        sz  = PARA_MIN(((size_t)afhi->chunks_total + 1) * 4, ct->size) + 1;
-       afhi->chunk_table = para_malloc(sz);
+       afhi->chunk_table = alloc(sz);
        for (i = 0; i <= afhi->chunks_total && i * 4 + 3 < ct->size; i++)
                afhi->chunk_table[i] = read_u32(ct->data + 4 * i);
 }
@@ -1066,7 +1066,7 @@ again:
        if (ret < 0)
                return ret;
        if (!d->hash)
-               d->hash = para_malloc(HASH_SIZE);
+               d->hash = alloc(HASH_SIZE);
        memcpy(d->hash, tmp_hash, HASH_SIZE);
        free(d->path);
        ret = get_audio_file_path_of_row(current_aft_row, &d->path);
@@ -1224,7 +1224,7 @@ static int sort_matching_paths(struct ls_options *options)
        int (*compar)(const void *, const void *);
        int i;
 
-       options->data_ptr = para_malloc(nmemb * sizeof(*options->data_ptr));
+       options->data_ptr = arr_alloc(nmemb, sizeof(*options->data_ptr));
        for (i = 0; i < nmemb; i++)
                options->data_ptr[i] = options->data + i;
 
@@ -1317,8 +1317,8 @@ static int prepare_ls_row(struct osl_row *row, void *ls_opts)
        if (options->num_matching_paths > options->array_size) {
                options->array_size++;
                options->array_size *= 2;
-               options->data = para_realloc(options->data, options->array_size
-                       sizeof(*options->data));
+               options->data = arr_realloc(options->data, options->array_size,
+                       sizeof(*options->data));
        }
        d = options->data + tmp;
        ret = get_afsi_of_row(aft_row, &d->afsi);
@@ -1424,7 +1424,7 @@ static int com_ls(struct command_context *cc, struct lls_parse_result *lpr)
        ret = lls_serialize_parse_result(lpr, cmd, NULL, &query.size);
        assert(ret >= 0);
        query.size += sizeof(*opts);
-       query.data = para_malloc(query.size);
+       query.data = alloc(query.size);
        opts = query.data;
        memset(opts, 0, sizeof(*opts));
        slpr = query.data + sizeof(*opts);
@@ -1553,7 +1553,7 @@ static void save_add_callback_buffer(unsigned char *hash, const char *path,
        size_t afhi_size = sizeof_afhi_buf(afhi);
        size_t size = CAB_PATH_OFFSET + path_len + afhi_size
                + sizeof_chunk_table(afhi) + slpr_size;
-       char *buf = para_malloc(size);
+       char *buf = alloc(size);
        uint32_t pos;
 
        assert(size <= ~(uint32_t)0);
@@ -2320,7 +2320,7 @@ static int com_setatt_callback(struct afs_callback_arg *aca)
                                goto out; /* no attribute modifier given */
                        goto set_atts;
                }
-               p = para_malloc(len);
+               p = alloc(len);
                memcpy(p, arg, len - 1);
                p[len - 1] = '\0';
                ret = get_attribute_bitnum_by_name(p, &bitnum);
index 1d81e5d9dbabbcef772d182eabe6a03ba5a51915..af4adc46382da236e7fec5786fa3d40234f16546 100644 (file)
@@ -52,7 +52,7 @@ static int alsa_mix_open(const char *dev, struct mixer_handle **handle)
 
        PARA_INFO_LOG("snd_mixer_{open,attach,register,load}\n");
        *handle = NULL;
-       h = para_calloc(sizeof(*h));
+       h = zalloc(sizeof(*h));
        h->card = para_strdup(dev? dev : "hw:0");
        ret = snd_mixer_open(&h->mixer, 0);
        if (ret < 0) {
index 2bf3fd0e9010539fa6784e554ae7dc8c21441d3d..92d6cb703b7a4911d0b5aa61282f703ce0bb490c 100644 (file)
@@ -296,7 +296,7 @@ again:
 
                if (bytes == 0) /* no data available */
                        return 0;
-               pad = wn->private_data = para_calloc(sizeof(*pad));
+               pad = wn->private_data = zalloc(sizeof(*pad));
                ret = get_btr_sample_rate(btrn, &val);
                if (ret < 0)
                        goto err;
index 9369e4bcbeb1f9c9eec251f5136a34d9e223f8bb..360e3fc2d7429bb7aa8219248ff4d38505a86ac2 100644 (file)
@@ -29,7 +29,7 @@ static void amp_close(struct filter_node *fn)
 
 static void amp_open(struct filter_node *fn)
 {
-       struct private_amp_data *pad = para_calloc(sizeof(*pad));
+       struct private_amp_data *pad = zalloc(sizeof(*pad));
        unsigned given = FILTER_CMD_OPT_GIVEN(AMP, AMP, fn->lpr);
        uint32_t amp_arg = FILTER_CMD_OPT_UINT32_VAL(AMP, AMP, fn->lpr);
 
@@ -74,7 +74,7 @@ next_buffer:
        if (inplace)
                out = in;
        else
-               out = para_malloc(len * 2);
+               out = alloc(len * 2);
 
        for (i = 0; i < len; i++) {
                int x = (in[i] * factor) >> 6;
index 41e609b70ab089acc384fb48c4fc40c58657c711..950f8f73808e0b6528c0b73a2a43da58ec17f4ee 100644 (file)
@@ -184,7 +184,7 @@ static int aow_init(struct writer_node *wn, unsigned sample_rate,
        ao_info *info;
        const struct lls_opt_result *r;
        unsigned n;
-       struct private_aow_data *pawd = para_malloc(sizeof(*pawd));
+       struct private_aow_data *pawd = alloc(sizeof(*pawd));
 
        ao_initialize();
        aow_show_drivers();
index 5f91e3b7d925bf4bd34f67ef0cfeb059a60cef8f..d6c14cbcf7245a3a7db4bb3f86cf7e35efb8384b 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -171,7 +171,7 @@ static int audioc_post_monitor(struct sched *s, void *context)
        if (!sched_read_ok(at->fd, s))
                return 0;
        bufsize = PARA_MAX(1024U, OPT_UINT32_VAL(BUFSIZE));
-       buf = para_malloc(bufsize);
+       buf = alloc(bufsize);
        ret = recv_bin_buffer(at->fd, buf, bufsize);
        PARA_DEBUG_LOG("recv: %d\n", ret);
        if (ret == 0)
@@ -370,7 +370,7 @@ int main(int argc, char *argv[])
        if (ret < 0)
                goto out;
        bufsize = PARA_MAX(1024U, OPT_UINT32_VAL(BUFSIZE));
-       buf = para_malloc(bufsize);
+       buf = alloc(bufsize);
        do {
                size_t n = ret = recv_bin_buffer(fd, buf, bufsize);
                if (ret <= 0)
index c29cf3ad472dc56a3b5328d2ca9e85e8ea45e288..0e8e5981085b7d05b8a2a08f35a9bb7944a4d72d 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -391,7 +391,7 @@ static void parse_config_or_die(void)
        n = OPT_GIVEN(USER_ALLOW);
        if (n == 0)
                return;
-       uid_whitelist = para_malloc(n * sizeof(uid_t));
+       uid_whitelist = arr_alloc(n, sizeof(uid_t));
        for (i = 0; i < n; i++) {
                const char *arg = lls_string_val(i, OPT_RESULT(USER_ALLOW));
                int32_t val;
@@ -562,7 +562,7 @@ static void open_filters(struct slot_info *s)
                return;
        PARA_INFO_LOG("opening %s filters\n", audio_formats[s->format]);
        assert(s->fns == NULL);
-       s->fns = para_calloc(nf * sizeof(struct filter_node));
+       s->fns = zalloc(nf * sizeof(struct filter_node));
        parent = s->receiver_node->btrn;
        for (i = 0; i < nf; i++) {
                char buf[20];
@@ -600,7 +600,7 @@ static void open_writers(struct slot_info *s)
        struct btr_node *parent = s->fns[a->num_filters - 1].btrn;
 
        assert(s->wns == NULL);
-       s->wns = para_calloc(PARA_MAX(1U, a->num_writers)
+       s->wns = zalloc(PARA_MAX(1U, a->num_writers)
                * sizeof(struct writer_node));
        for (i = 0; i < a->num_writers; i++) {
                wn = s->wns + i;
@@ -627,7 +627,7 @@ static int open_receiver(int format)
        if (ret < 0)
                return ret;
        slot_num = ret;
-       rn = para_calloc(sizeof(*rn));
+       rn = zalloc(sizeof(*rn));
        rn->receiver = r;
        rn->lpr = a->receiver_lpr;
        rn->btrn = btr_new_node(&(struct btr_node_description)
@@ -817,7 +817,7 @@ static int parse_stream_command(const char *txt, const char **cmd)
                return -E_MISSING_COLON;
        *cmd = p + 1;
        len = p - txt;
-       re = para_malloc(len + 1);
+       re = alloc(len + 1);
        strncpy(re, txt, len);
        re[len] = '\0';
        ret = get_matching_audio_format_nums(re);
@@ -833,12 +833,9 @@ static int add_filter(int format, const char *cmdline)
        struct lls_parse_result *flpr;
 
        filter_num = filter_setup(cmdline, &cfg, &flpr);
-       a->filter_lpr = para_realloc(a->filter_lpr,
-               (nf + 1) * sizeof(flpr));
-       a->filter_conf = para_realloc(a->filter_conf,
-               (nf + 1) * sizeof(void *));
-       a->filter_nums = para_realloc(a->filter_nums,
-               (nf + 1) * sizeof(unsigned));
+       a->filter_lpr = arr_realloc(a->filter_lpr, nf + 1, sizeof(flpr));
+       a->filter_conf = arr_realloc(a->filter_conf, nf + 1, sizeof(void *));
+       a->filter_nums = arr_realloc(a->filter_nums, nf + 1, sizeof(unsigned));
 
        a->filter_nums[nf] = filter_num;
        a->filter_conf[nf] = cfg;
@@ -884,8 +881,8 @@ static int parse_writer_args(void)
                if (a->num_writers > 0)
                        continue; /* already set up */
                a->num_writers = 1;
-               a->wids = para_malloc(sizeof(int));
-               a->writer_lpr = para_malloc(sizeof(struct lls_parse_result *));
+               a->wids = alloc(sizeof(int));
+               a->writer_lpr = alloc(sizeof(struct lls_parse_result *));
                a->wids[0] = check_writer_arg_or_die(NULL, a->writer_lpr);
                PARA_INFO_LOG("%s writer: %s (default)\n", audio_formats[i],
                        writer_name(a->wids[0]));
index 29c330f36a526d1004cb8595248fb75008033438..6e2f8ee9e4aaf446267270e3be2398a4ee6d7c96 100644 (file)
@@ -114,7 +114,7 @@ static int stat_client_add(int fd, uint64_t mask, int parser_friendly)
        ret = dup(fd);
        if (ret < 0)
                return -ERRNO_TO_PARA_ERROR(errno);
-       new_client = para_calloc(sizeof(*new_client));
+       new_client = zalloc(sizeof(*new_client));
        new_client->fd = ret;
        PARA_INFO_LOG("adding client on fd %d\n", new_client->fd);
        new_client->item_mask = mask;
index 122465f8feea79cf06d09bfd759d2446ee0f3f12..ac6f65aa85d469df3ba4a70a058ed85b31eb6d11 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -79,7 +79,7 @@ int base64_decode(char const *src, size_t encoded_size, char **result,
 
        if (encoded_size == (size_t)-1)
                encoded_size = strlen(src);
-       target = para_malloc(BASE64_MAX_DECODED_SIZE(encoded_size) + 1);
+       target = alloc(BASE64_MAX_DECODED_SIZE(encoded_size) + 1);
 
        for (
                i = 0, j = 0, state = 0;
index dfc1e55e67aced611014fc90b86128e8bd61a457..a1c7c943138d41993807109be09969a58e914a0b 100644 (file)
@@ -46,8 +46,8 @@ static void alloc_table(struct vlc *vlc, int size)
        vlc->table_size += size;
        if (vlc->table_size > vlc->table_allocated) {
                vlc->table_allocated += (1 << vlc->bits);
-               vlc->table = para_realloc(vlc->table,
-                       sizeof(int16_t) * 2 * vlc->table_allocated);
+               vlc->table = arr_realloc(vlc->table, vlc->table_allocated,
+                       sizeof(int16_t) * 2);
        }
 }
 
diff --git a/blob.c b/blob.c
index 4ecbc45bb15f42c15342e7900f4de94522ef45bb..b63724014138513dfb89d4300cb38056bfaa601a 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -403,7 +403,7 @@ static int stdin_command(struct command_context *cc,
        if (ret < 0)
                return ret;
        query.size = len + 1 + stdin_obj.size;
-       query.data = para_malloc(query.size);
+       query.data = alloc(query.size);
        memcpy(query.data, lls_input(0, lpr), len + 1);
        if (stdin_obj.size > 0)
                memcpy((char *)query.data + len + 1, stdin_obj.data,
index 49e40fb952c2e6c36a62001b1bc0a46601f412e6..05cdfa83630004e49561f0c7bef0138bd0a35c27 100644 (file)
@@ -72,8 +72,8 @@ struct btr_pool *btr_pool_new(const char *name, size_t area_size)
        struct btr_pool *btrp;
 
        PARA_INFO_LOG("%s, %zu bytes\n", name, area_size);
-       btrp = para_malloc(sizeof(*btrp));
-       btrp->area_start = para_malloc(area_size);
+       btrp = alloc(sizeof(*btrp));
+       btrp->area_start = alloc(area_size);
        btrp->area_end = btrp->area_start + area_size;
        btrp->rhead = btrp->area_start;
        btrp->whead = btrp->area_start;
@@ -262,7 +262,7 @@ static void btr_pool_deallocate(struct btr_pool *btrp, size_t size)
  */
 struct btr_node *btr_new_node(struct btr_node_description *bnd)
 {
-       struct btr_node *btrn = para_malloc(sizeof(*btrn));
+       struct btr_node *btrn = alloc(sizeof(*btrn));
 
        btrn->name = para_strdup(bnd->name);
        btrn->parent = bnd->parent;
@@ -307,7 +307,7 @@ out:
  */
 static struct btr_buffer *new_btrb(char *buf, size_t size)
 {
-       struct btr_buffer *btrb = para_calloc(sizeof(*btrb));
+       struct btr_buffer *btrb = zalloc(sizeof(*btrb));
 
        btrb->buf = buf;
        btrb->size = size;
@@ -354,7 +354,7 @@ static void add_btrb_to_children(struct btr_buffer *btrb,
        if (btrn->start.tv_sec == 0)
                btrn->start = *now;
        FOR_EACH_CHILD(ch, btrn) {
-               struct btr_buffer_reference *br = para_calloc(sizeof(*br));
+               struct btr_buffer_reference *br = zalloc(sizeof(*br));
                br->btrb = btrb;
                br->consumed = consumed;
                list_add_tail(&br->node, &ch->input_queue);
@@ -1007,12 +1007,12 @@ next:
        if (!wbr) {
                /* Make a new wrap buffer combining buf1 and buf2. */
                sz = sz1 + sz2;
-               buf = para_malloc(sz);
+               buf = alloc(sz);
                PARA_DEBUG_LOG("merging input buffers: (%p:%zu, %p:%zu) -> %p:%zu\n",
                        buf1, sz1, buf2, sz2, buf, sz);
                memcpy(buf, buf1, sz1);
                memcpy(buf + sz1, buf2, sz2);
-               br = para_calloc(sizeof(*br));
+               br = zalloc(sizeof(*br));
                br->btrb = new_btrb(buf, sz);
                br->btrb->refcount = 1;
                br->consumed = 0;
@@ -1067,13 +1067,13 @@ static int merge_input(struct btr_node *btrn)
        assert(i == 2);
        /* make a new btrb that combines the two buffers and a br to it. */
        sz = szs[0] + szs[1];
-       buf = para_malloc(sz);
+       buf = alloc(sz);
        PARA_DEBUG_LOG("%s: memory merging input buffers: (%zu, %zu) -> %zu\n",
                btrn->name, szs[0], szs[1], sz);
        memcpy(buf, bufs[0], szs[0]);
        memcpy(buf + szs[0], bufs[1], szs[1]);
 
-       br = para_calloc(sizeof(*br));
+       br = zalloc(sizeof(*br));
        br->btrb = new_btrb(buf, sz);
        br->btrb->refcount = 1;
 
index 100975dc79c4b5a0daf78facfbc632d2e9972916..3789f30aa5a20ef5433df83362a6be02563c8d17 100644 (file)
@@ -207,7 +207,7 @@ struct check_wav_context *check_wav_init(struct btr_node *parent,
                struct btr_node *child, struct wav_params *params,
                struct btr_node **cw_btrn)
 {
-       struct check_wav_context *cwc = para_calloc(sizeof(*cwc));
+       struct check_wav_context *cwc = zalloc(sizeof(*cwc));
 
        cwc->state = CWS_NEED_HEADER;
        cwc->min_iqs = WAV_HEADER_LEN;
index cf74cc336de25caa593b198bcfd79a3166996381..1f11359fcb16e4e55073a5fd36d5d5cff7f5504c 100644 (file)
@@ -52,7 +52,7 @@ int cq_enqueue(struct chunk_queue *cq, const char *buf, size_t num_bytes)
 
        if (cq->num_pending + num_bytes > cq->max_pending)
                return -E_QUEUE;
-       qc = para_malloc(sizeof(struct queued_chunk));
+       qc = alloc(sizeof(struct queued_chunk));
        cq->num_pending += num_bytes;
        qc->buf = buf;
        qc->num_bytes = num_bytes;
@@ -130,7 +130,7 @@ int cq_get(struct queued_chunk *qc, const char **buf, size_t *num_bytes)
  */
 struct chunk_queue *cq_new(size_t max_pending)
 {
-       struct chunk_queue *cq = para_malloc(sizeof(*cq));
+       struct chunk_queue *cq = alloc(sizeof(*cq));
        init_list_head(&cq->q);
        cq->max_pending = max_pending;
        cq->num_pending = 0;
index 36e851f4b571a2dc095290f18f5e0d96afc5331e..a6aee0f8b9afc79439032db3695ba9c82bb594a1 100644 (file)
--- a/client.c
+++ b/client.c
@@ -347,7 +347,7 @@ static void setatt_completer(struct i9e_completion_info *ci,
        if (ret < 0)
                goto out;
        num_atts = ret;
-       sl = para_realloc(sl, (2 * num_atts + 1) * sizeof(char *));
+       sl = arr_realloc(sl, 2 * num_atts + 1, sizeof(char *));
        for (i = 0; i < num_atts; i++) {
                char *orig = sl[i];
                sl[i] = make_message("%s+", orig);
@@ -441,7 +441,7 @@ static void select_completer(struct i9e_completion_info *ci,
                goto free_moods;
        num_pl = ret;
        n = num_moods + num_pl;
-       mops = para_malloc((n + 1) * sizeof(char *));
+       mops = arr_alloc(n + 1, sizeof(char *));
        for (i = 0; i < num_moods; i++)
                mops[i] = make_message("m/%s", moods[i]);
        for (i = 0; i < num_pl; i++)
index 3beeed1f49effebe1d6f92ceea0fdebb589a7fe6..f476a1c4ada24ddf4a7c5a825048ab7df9e7d9f5 100644 (file)
@@ -245,7 +245,7 @@ static int send_sb_command(struct client_task *ct)
 
        for (i = 0; i < num_inputs; i++)
                len += strlen(lls_input(i, ct->lpr)) + 1;
-       p = command = para_malloc(len);
+       p = command = alloc(len);
        for (i = 0; i < num_inputs; i++) {
                const char *str = lls_input(i, ct->lpr);
                strcpy(p, str);
@@ -336,8 +336,7 @@ static int client_post_monitor(struct sched *s, void *context)
                free(sbb.iov.iov_base);
                if (ret < 0)
                        goto out;
-               ct->challenge_hash = para_malloc(HASH2_SIZE);
-
+               ct->challenge_hash = alloc(HASH2_SIZE);
                if (has_feature("sha256", ct)) {
                        hash2_function((char *)crypt_buf, APC_CHALLENGE_SIZE, ct->challenge_hash);
                        hash2_to_asc(ct->challenge_hash, buf);
@@ -582,7 +581,7 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
        PARA_INFO_LOG("user: %s\n", user);
        PARA_INFO_LOG("key file: %s\n", kf);
        PARA_INFO_LOG("loglevel: %d\n", ll);
-       ct = para_calloc(sizeof(*ct));
+       ct = zalloc(sizeof(*ct));
        ct->scc.fd = -1;
        ct->lpr = lpr;
        ct->key_file = kf;
index 7b464d09cab0ed446aac327fbba6d32f9aadd7b3..809f027e278d44f4413482ba433b8893b8be0843 100644 (file)
@@ -31,7 +31,7 @@ struct close_on_fork {
  */
 void add_close_on_fork_list(int fd)
 {
-       struct close_on_fork *cof = para_malloc(sizeof(struct close_on_fork));
+       struct close_on_fork *cof = alloc(sizeof(struct close_on_fork));
 
        if (!initialized) {
                init_list_head(&close_on_fork_list);
index 0f47110e54b7e661e59b8895e7c79847ad35bae4..a0102eebe42db14df8bf9893efec500fc56bf6f1 100644 (file)
--- a/command.c
+++ b/command.c
@@ -78,7 +78,7 @@ static char *vss_status_tohuman(unsigned int flags)
  */
 static char *vss_get_status_flags(unsigned int flags)
 {
-       char *msg = para_malloc(5 * sizeof(char));
+       char *msg = alloc(5 * sizeof(char));
 
        msg[0] = (flags & VSS_PLAYING)? 'P' : '_';
        msg[1] = (flags & VSS_NOMORE)? 'O' : '_';
@@ -871,7 +871,7 @@ static int run_command(struct command_context *cc, struct iovec *iov)
        for (i = 0; p < end; i++)
                p += strlen(p) + 1;
        argc = i;
-       argv = para_malloc((argc + 1) * sizeof(char *));
+       argv = arr_alloc(argc + 1, sizeof(char *));
        for (i = 0, p = iov->iov_base; p < end; i++) {
                argv[i] = para_strdup(p);
                p += strlen(p) + 1;
@@ -926,7 +926,7 @@ int handle_connect(int fd)
        int ret;
        unsigned char rand_buf[APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
        unsigned char challenge_hash[HASH2_SIZE];
-       char *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
+       char *command = NULL, *buf = alloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
        size_t numbytes;
        struct command_context cc_struct = {.u = NULL}, *cc = &cc_struct;
        struct iovec iov;
index 9f9d8515e3794139a65f9f3e7598d3d900829bcc..a6a001919acc5038039d5de0b0590a265052e978 100644 (file)
@@ -66,7 +66,7 @@ next_buffer:
        if (inplace)
                op = ip;
        else
-               op = para_malloc(length);
+               op = alloc(length);
        for (i = 0; i < length / 2; i++) {
                /* be careful in that heat, my dear */
                int sample = *ip++;
@@ -116,7 +116,7 @@ err:
 
 static void compress_open(struct filter_node *fn)
 {
-       struct private_compress_data *pcd = para_calloc(sizeof(*pcd));
+       struct private_compress_data *pcd = zalloc(sizeof(*pcd));
        uint32_t inertia = U32_OPTVAL(INERTIA, fn->lpr);
        uint32_t aggressiveness = U32_OPTVAL(AGGRESSIVENESS, fn->lpr);
 
index 3a44dbdddcd1cf59108ba110c8d83c4fac11d609..d7471235682855d3f376f0d5796b39567498937b 100644 (file)
@@ -317,7 +317,7 @@ int decode_private_key(const char *key_file, unsigned char **result,
                goto unmap;
 
        key_size = footer - begin;
-       key = para_malloc(key_size + 1);
+       key = alloc(key_size + 1);
        for (i = 0, j = 0; begin + i < footer; i++) {
                if (para_isspace(begin[i]))
                        continue;
index faacd39f8fb0b4377f495a63d115ba5bd3de0336..fe2f7abf2af5fdb9abb27dcfb41c9da705ebf91a 100644 (file)
@@ -76,7 +76,7 @@ static int dccp_recv_open(struct receiver_node *rn)
        /* Copy CCID preference list (u8 array required) */
        given = lls_opt_given(r_c);
        if (given) {
-               ccids = para_malloc(given);
+               ccids = alloc(given);
                fo = flowopt_new();
                for (i = 0; i < given; i++)
                        ccids[i] = lls_int32_val(i, r_c);
index 9e9372715c5fac244ed5943d74e3d98089859831..15a361babfa8570f61d2b51c15e60c83a8bab009 100644 (file)
@@ -147,7 +147,7 @@ static void dccp_post_monitor(__a_unused struct sched *s)
                shutdown_client(sc, dss);
                return;
        }
-       dfc = para_calloc(sizeof(*dfc));
+       dfc = zalloc(sizeof(*dfc));
        sc->private_data = dfc;
        k = OPT_UINT32_VAL(DCCP_DATA_SLICES_PER_GROUP);
        n = OPT_UINT32_VAL(DCCP_SLICES_PER_GROUP);
diff --git a/fd.c b/fd.c
index 800106e132b2bc21085f65803d70b6bad492f854..763f756cdc3b5086ee9d26f432dbbfb760e02e4a 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -269,7 +269,7 @@ int read_nonblock(int fd, void *buf, size_t sz, size_t *num_bytes)
 int read_pattern(int fd, const char *pattern, size_t bufsize)
 {
        size_t n, len;
-       char *buf = para_malloc(bufsize + 1);
+       char *buf = alloc(bufsize + 1);
        int ret = read_nonblock(fd, buf, bufsize, &n);
 
        buf[n] = '\0';
diff --git a/fec.c b/fec.c
index 2301cc8d2d4653b8bc82a8bcc46b5867b5d7af14..932e0693e3786fc28b5a180428a9b296534a1fd5 100644 (file)
--- a/fec.c
+++ b/fec.c
@@ -97,7 +97,7 @@ static void init_mul_table(void)
 
 static unsigned char *alloc_matrix(int rows, int cols)
 {
-       return para_malloc(rows * cols);
+       return arr_alloc(rows, cols);
 }
 
 /*
@@ -245,9 +245,9 @@ static void matmul(unsigned char *a, unsigned char *b, unsigned char *c,
 static int invert_mat(unsigned char *src, int k)
 {
        int irow, icol, row, col, ix, error;
-       int *indxc = para_malloc(k * sizeof(int));
-       int *indxr = para_malloc(k * sizeof(int));
-       int *ipiv = para_malloc(k * sizeof(int)); /* elements used as pivots */
+       int *indxc = arr_alloc(k, sizeof(int));
+       int *indxr = arr_alloc(k, sizeof(int));
+       int *ipiv = arr_alloc(k, sizeof(int)); /* elements used as pivots */
        unsigned char c, *p, *id_row = alloc_matrix(1, k),
                *temp_row = alloc_matrix(1, k);
 
@@ -371,9 +371,9 @@ static void invert_vdm(unsigned char *src, int k)
         * c holds the coefficient of P(x) = Prod (x - p_i), i=0..k-1
         * b holds the coefficient for the matrix inversion
         */
-       c = para_malloc(k);
-       b = para_malloc(k);
-       p = para_malloc(k);
+       c = alloc(k);
+       b = alloc(k);
+       p = alloc(k);
 
        for (j = 1, i = 0; i < k; i++, j += k) {
                c[i] = 0;
@@ -466,7 +466,7 @@ int fec_new(int k, int n, struct fec_parms **result)
 
        if (k < 1 || k > GF_SIZE + 1 || n > GF_SIZE + 1 || k > n)
                return -E_FEC_PARMS;
-       parms = para_malloc(sizeof(struct fec_parms));
+       parms = alloc(sizeof(struct fec_parms));
        parms->k = k;
        parms->n = n;
        parms->enc_matrix = alloc_matrix(n, k);
@@ -607,10 +607,10 @@ int fec_decode(struct fec_parms *parms, unsigned char **data, int *idx,
        if (ret < 0)
                return ret;
        /* do the actual decoding */
-       slice = para_malloc(k * sizeof(unsigned char *));
+       slice = arr_alloc(k, sizeof(unsigned char *));
        for (row = 0; row < k; row++) {
                if (idx[row] >= k) {
-                       slice[row] = para_calloc(sz);
+                       slice[row] = zalloc(sz);
                        for (col = 0; col < k; col++)
                                addmul(slice[row], data[col],
                                        m_dec[row * k + col], sz);
index d629603c4b11f37825cd71b7bf5335d65625fa83..1d8fbc16db71094d4f81b2c8c6bb88014087582c 100644 (file)
@@ -225,8 +225,8 @@ static int add_slice(char *buf, struct fecdec_group *fg)
        }
        if (fg->num_slices == 0) {
                fg->num_slices = fg->h.slices_per_group;
-               fg->idx = para_malloc(fg->num_slices * sizeof(int));
-               fg->data = para_calloc(fg->num_slices * sizeof(unsigned char *));
+               fg->idx = arr_alloc(fg->num_slices, sizeof(int));
+               fg->data = arr_zalloc(fg->num_slices, sizeof(unsigned char *));
        }
        r = fg->num_received_slices;
        /* Check if we already have this slice. */
@@ -236,7 +236,7 @@ static int add_slice(char *buf, struct fecdec_group *fg)
                return 0;
        }
        fg->idx[r] = slice_num;
-       fg->data[r] = para_malloc(fg->h.slice_bytes);
+       fg->data[r] = alloc(fg->h.slice_bytes);
        memcpy(fg->data[r], buf, fg->h.slice_bytes);
        fg->num_received_slices++;
        return 1;
@@ -471,7 +471,7 @@ out:
 static void fecdec_open(struct filter_node *fn)
 {
        struct private_fecdec_data *pfd;
-       pfd = para_calloc(sizeof(*pfd));
+       pfd = zalloc(sizeof(*pfd));
        fn->private_data = pfd;
        fn->min_iqs = FEC_HEADER_SIZE;
 }
index 64153178e969191201b869fe6bfa34f37f61af23..ba902070d9498677e94872860aeb9bbcbcd5235e 100644 (file)
@@ -64,7 +64,7 @@ static int prepare_output_file(struct writer_node *wn)
                close(fd);
                return ret;
        }
-       pfwd = wn->private_data = para_calloc(sizeof(*pfwd));
+       pfwd = wn->private_data = zalloc(sizeof(*pfwd));
        pfwd->fd = fd;
        return 1;
 }
index 85d3da7e57270e21ec6897c3086c93397f9b5e31..722cb16fb35bfaec09bbaca046ebf62931df8036 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -120,14 +120,14 @@ int main(int argc, char *argv[])
                EMBRACE(.name = "stdin"));
        stdin_task_register(sit, &s);
 
-       fns = para_malloc(OPT_GIVEN(FILTER) * sizeof(*fns));
+       fns = arr_alloc(OPT_GIVEN(FILTER), sizeof(*fns));
        for (i = 0, parent = sit->btrn; i < OPT_GIVEN(FILTER); i++) {
                const char *fa = lls_string_val(i, OPT_RESULT(FILTER));
                const char *name;
                struct filter_node *fn;
                struct task_info ti;
 
-               fn = fns[i] = para_calloc(sizeof(*fn));
+               fn = fns[i] = zalloc(sizeof(*fn));
                fn->filter_num = filter_setup(fa, &fn->conf, &filter_lpr);
                name = filter_name(fn->filter_num);
                fn->lpr = filter_lpr;
index 6e23683937f6932aaa739095ef8281fc9075da55..2b5b6c1d9aa758e3d2e769756cc3d75f3bb57120 100644 (file)
@@ -374,8 +374,8 @@ static int flac_afh_read_chunks(struct private_flac_afh_data *pfad)
                        goto free_decoder;
                if (c >= chunk_table_size) {
                        chunk_table_size = 2 * chunk_table_size + 100;
-                       afhi->chunk_table = para_realloc(afhi->chunk_table,
-                               chunk_table_size * sizeof(uint32_t));
+                       afhi->chunk_table = arr_realloc(afhi->chunk_table,
+                               chunk_table_size, sizeof(uint32_t));
                }
                afhi->chunk_table[c] = pos;
 
@@ -481,7 +481,7 @@ static int flac_rewrite_tags(const char *map, size_t map_bytes,
        FLAC__Metadata_Iterator *iter;
        FLAC__StreamMetadata *b = NULL;
        FLAC__bool ok;
-       struct private_flac_afh_data *pfad = para_calloc(sizeof(*pfad));
+       struct private_flac_afh_data *pfad = zalloc(sizeof(*pfad));
 
        pfad->map = map;
        pfad->map_bytes = map_bytes;
index 2c9f8607c0d7603664ef13acd3a418f13625b8f7..f3060f5721c1c22753cceb4229ee4dbe178dbf52 100644 (file)
@@ -135,7 +135,7 @@ static FLAC__StreamDecoderWriteStatus write_cb(
        struct btr_node *btrn = fn->btrn;
        size_t k, n = frame->header.blocksize;
        unsigned channels = FLAC__stream_decoder_get_channels(decoder);
-       char *outbuffer = para_malloc(n * channels * 2);
+       char *outbuffer = arr_alloc(n, channels * 2);
 
        if (channels == 1) {
                for (k = 0; k < n; k++) {
@@ -286,7 +286,7 @@ static void flacdec_close(struct filter_node *fn)
 
 static void flacdec_open(struct filter_node *fn)
 {
-       struct private_flacdec_data *pfd = para_calloc(sizeof(*pfd));
+       struct private_flacdec_data *pfd = zalloc(sizeof(*pfd));
        fn->private_data = pfd;
        fn->min_iqs = 0;
 }
index 506f0bb84e6c199d065942553935dc27a8833d93..763fa6de3252d2f5f188fc3f447f2029d0f5775a 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -406,7 +406,7 @@ static int get_private_key(const char *key_file, struct asymmetric_key **result)
                ret = -E_SEXP_BUILD;
                goto free_params;
        }
-       key = para_malloc(sizeof(*key));
+       key = alloc(sizeof(*key));
        key->sexp = sexp;
        *result = key;
        ret = bits;
@@ -456,7 +456,7 @@ int apc_get_pubkey(const char *key_file, struct asymmetric_key **result)
                goto release_n;
        }
        PARA_INFO_LOG("successfully read %u bit ssh public key\n", bits);
-       key = para_malloc(sizeof(*key));
+       key = alloc(sizeof(*key));
        key->num_bytes = ret;
        key->sexp = sexp;
        *result = key;
@@ -624,7 +624,7 @@ struct stream_cipher {
 struct stream_cipher *sc_new(const unsigned char *data, int len)
 {
        gcry_error_t gret;
-       struct stream_cipher *sc = para_malloc(sizeof(*sc));
+       struct stream_cipher *sc = alloc(sizeof(*sc));
 
        assert(len >= 2 * AES_CRT128_BLOCK_SIZE);
        gret = gcry_cipher_open(&sc->handle, GCRY_CIPHER_AES128,
index 393e2ce331117a6d29231f551b78103b6bfe9f83..1019e579a39d8559b2aecc658c7651fd6b7704dc 100644 (file)
@@ -261,7 +261,7 @@ static int gc_check_args(struct lls_parse_result *lpr, struct grab_client *gc)
 int grab_client_new(int fd, struct lls_parse_result *lpr, struct sched *s)
 {
        int ret;
-       struct grab_client *gc = para_calloc(sizeof(struct grab_client));
+       struct grab_client *gc = zalloc(sizeof(struct grab_client));
 
        ret = gc_check_args(lpr, gc);
        if (ret < 0)
diff --git a/gui.c b/gui.c
index 72908f23e46d0762ab4442975070dc5bd46c7269..ebfab3564836e7b1708dc430e9375815b00d49b7 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -431,7 +431,7 @@ static void rb_add_entry(int color, char *msg)
 
        if (strwidth(msg, &len) < 0)
                return;
-       new = para_malloc(sizeof(struct rb_entry));
+       new = alloc(sizeof(struct rb_entry));
        new->color = color;
        new->len = len;
        new->msg = msg;
index 59e9696b47e082f09bf6c58ccf49eadb3c3153e9..5aafacb840df1f863536fac1911c8d1caf8eb2b0 100644 (file)
@@ -160,7 +160,7 @@ static int http_recv_open(struct receiver_node *rn)
                close(fd);
                return ret;
        }
-       rn->private_data = phd = para_calloc(sizeof(struct private_http_recv_data));
+       rn->private_data = phd = zalloc(sizeof(struct private_http_recv_data));
        rn->fd = fd;
        phd->status = HTTP_CONNECTED;
        rn->btrp = btr_pool_new("http_recv", 320 * 1024);
index 0a90e8840cdf76e683a276d569fba3bfcd710c2b..90e3ee57d1b6d40152ef6fc4026331766e2524c5 100644 (file)
@@ -191,7 +191,7 @@ static void http_post_monitor(__a_unused struct sched *s)
        sc = accept_sender_client(hss);
        if (!sc)
                return;
-       phsd = para_malloc(sizeof(*phsd));
+       phsd = alloc(sizeof(*phsd));
        sc->private_data = phsd;
        phsd->status = HTTP_CONNECTED;
 }
diff --git a/imdct.c b/imdct.c
index 93577b5451a0cbb8c8da58e997a9f4d77179243e..2e1089f1f818be4bcdeb20be3d4d7a865943e00e 100644 (file)
--- a/imdct.c
+++ b/imdct.c
@@ -336,7 +336,7 @@ static int fft_init(struct fft_context *s, int nbits)
        s->nbits = nbits;
        n = 1 << nbits;
 
-       s->revtab = para_malloc(n * sizeof(uint16_t));
+       s->revtab = arr_alloc(n, sizeof(uint16_t));
        for (j = 4; j <= nbits; j++) {
                int k = 1 << j;
                double freq = 2 * M_PI / k;
@@ -366,13 +366,13 @@ int imdct_init(int nbits, struct mdct_context **result)
        double alpha;
        struct mdct_context *s;
 
-       s = para_calloc(sizeof(*s));
+       s = zalloc(sizeof(*s));
        n = 1 << nbits;
        s->nbits = nbits;
        s->n = n;
        n4 = n >> 2;
-       s->tcos = para_malloc(n4 * sizeof(fftsample_t));
-       s->tsin = para_malloc(n4 * sizeof(fftsample_t));
+       s->tcos = arr_alloc(n4, sizeof(fftsample_t));
+       s->tsin = arr_alloc(n4, sizeof(fftsample_t));
 
        for (i = 0; i < n4; i++) {
                alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;
index 6c9110fd66e23cae6b8de5f80db834738565c64d..e367a65920c53982af55436d7b96ea53138408f8 100644 (file)
@@ -634,7 +634,7 @@ int i9e_poll(struct pollfd *fds, nfds_t nfds, int timeout)
 int i9e_extract_completions(const char *word, char **string_list,
                char ***result)
 {
-       char **matches = para_malloc(sizeof(char *));
+       char **matches = alloc(sizeof(char *));
        int match_count = 0, matches_len = 1;
        char **p;
        int len = strlen(word);
@@ -645,8 +645,8 @@ int i9e_extract_completions(const char *word, char **string_list,
                match_count++;
                if (match_count >= matches_len) {
                        matches_len *= 2;
-                       matches = para_realloc(matches,
-                               matches_len * sizeof(char *));
+                       matches = arr_realloc(matches, matches_len,
+                               sizeof(char *));
                }
                matches[match_count - 1] = para_strdup(*p);
        }
@@ -682,7 +682,7 @@ char **i9e_complete_commands(const char *word, struct i9e_completer *completers)
                if (is_prefix(word, cmd, len))
                        match_count++;
        }
-       matches = para_malloc((match_count + 1) * sizeof(*matches));
+       matches = arr_alloc(match_count + 1, sizeof(*matches));
        for (i = 0, match_count = 0; (cmd = completers[i].name); i++)
                if (is_prefix(word, cmd, len))
                        matches[match_count++] = para_strdup(cmd);
@@ -766,7 +766,7 @@ int i9e_print_completions(struct i9e_completer *completers)
        if (*p == ' ')
                p++;
        n = end - p + 1;
-       ci.word = para_malloc(n + 1);
+       ci.word = alloc(n + 1);
        strncpy(ci.word, p, n);
        ci.word[n] = '\0';
 create_matches:
diff --git a/mood.c b/mood.c
index b3f007b68fe07c46f500d1aaa7dffdfe9503f451..bcc9bc57d1a37520ca71f93d5d93a7fe1e2e2927 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -138,7 +138,7 @@ static void destroy_mood(struct mood *m)
 
 static struct mood *alloc_new_mood(const char *name)
 {
-       struct mood *m = para_calloc(sizeof(struct mood));
+       struct mood *m = zalloc(sizeof(struct mood));
        if (name)
                m->name = para_strdup(name);
        return m;
@@ -363,8 +363,8 @@ static int add_if_admissible(struct osl_row *aft_row, void *data)
        if (statistics.num >= aa->size) {
                aa->size *= 2;
                aa->size += 100;
-               aa->array = para_realloc(aa->array,
-                       aa->size * sizeof(struct osl_row *));
+               aa->array = arr_realloc(aa->array, aa->size,
+                       sizeof(struct osl_row *));
        }
        aa->array[statistics.num] = aft_row;
        return add_afs_statistics(aft_row);
diff --git a/mp.c b/mp.c
index c537e72998d2ae46e0e9dbaa55175eaebf14f07f..fb5a0c07472c46bb7d5ca42fcb4061d54755f96b 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -90,7 +90,7 @@ unsigned parse_quoted_string(const char *src, const char quote_chars[2],
 
        assert(len >= 2);
        assert(src[0] == quote_chars[0]);
-       p = dst = para_malloc(len - 1);
+       p = dst = alloc(len - 1);
        backslash = false;
        for (n = 1;; n++) {
                char c;
@@ -518,7 +518,7 @@ int mp_init(const char *definition, int nbytes, struct mp_context **result,
                        *errmsg = NULL;
                return 0;
        }
-       ctx = para_calloc(sizeof(*ctx));
+       ctx = zalloc(sizeof(*ctx));
        ctx->errmsg = NULL;
        ctx->ast = NULL;
 
index 728b25b81f94aa177a1e74ae01fca07419f7fe90..d7493ac01e28bba581b7112a41a37e84426be11a 100644 (file)
--- a/mp3_afh.c
+++ b/mp3_afh.c
@@ -348,7 +348,7 @@ static int mp3_rewrite_tags(const char *map, size_t mapsize,
        if (ret < 0)
                goto out;
        new_v2size = id3_tag_render(v2_tag, NULL);
-       v2_buffer = para_malloc(new_v2size);
+       v2_buffer = alloc(new_v2size);
        id3_tag_render(v2_tag, v2_buffer);
        PARA_INFO_LOG("writing v2 tag (%lu bytes)\n", new_v2size);
        ret = write_all(fd, (char *)v2_buffer, new_v2size);
@@ -598,7 +598,7 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
        const char *tag_versions[] = {"no", "id3v1", "id3v2", "id3v1+id3v2"};
 
        afhi->chunks_total = 0;
-       afhi->chunk_table = para_malloc(chunk_table_size * sizeof(uint32_t));
+       afhi->chunk_table = arr_alloc(chunk_table_size, sizeof(uint32_t));
        while (1) {
                int freq, br;
                struct timeval tmp, cct; /* current chunk time */
@@ -633,8 +633,8 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
                total_time = tmp;
                if (afhi->chunks_total >= chunk_table_size) {
                        chunk_table_size *= 2;
-                       afhi->chunk_table = para_realloc(afhi->chunk_table,
-                               chunk_table_size * sizeof(uint32_t));
+                       afhi->chunk_table = arr_realloc(afhi->chunk_table,
+                               chunk_table_size, sizeof(uint32_t));
                }
                afhi->chunk_table[afhi->chunks_total] = fpos;
                afhi->chunks_total++;
index 6a196f3a06c06a42ecca40fde56de3f0d3cf4926..bc8ccdaa99be724530372a03b71544abeece480b 100644 (file)
@@ -144,7 +144,7 @@ decode:
        }
        fn->min_iqs = 0;
        mad_synth_frame(&pmd->synth, &pmd->frame);
-       outbuffer = para_malloc(pmd->synth.pcm.length * 2 * pmd->channels);
+       outbuffer = arr_alloc(pmd->synth.pcm.length, 2 * pmd->channels);
        loaded = 0;
        for (i = 0; i < pmd->synth.pcm.length; i++) {
                int sample = MAD_TO_SHORT(pmd->synth.pcm.samples[0][i]);
@@ -166,7 +166,7 @@ err:
 
 static void mp3dec_open(struct filter_node *fn)
 {
-       struct private_mp3dec_data *pmd = para_calloc(sizeof(*pmd));
+       struct private_mp3dec_data *pmd = zalloc(sizeof(*pmd));
 
        fn->private_data = pmd;
        mad_stream_init(&pmd->stream);
diff --git a/mp4.c b/mp4.c
index 4b8607b185a9a87c845940d86412843654a13c7d..f8515ca290681a271155e9749d903ea9214b9b13 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -240,7 +240,7 @@ static int read_stsz(struct mp4 *f)
                return ret;
        if (t->stsz_sample_size != 0)
                return 1;
-       t->stsz_table = para_malloc(t->stsz_sample_count * sizeof(int32_t));
+       t->stsz_table = arr_alloc(t->stsz_sample_count, sizeof(int32_t));
        for (uint32_t n = 0; n < t->stsz_sample_count; n++) {
                ret = read_int32(f, &t->stsz_table[n]);
                if (ret <= 0)
@@ -260,8 +260,7 @@ static int read_stts(struct mp4 *f)
        ret = read_int32(f, &t->stts_entry_count);
        if (ret <= 0)
                return ret;
-       t->stts_sample_count = para_malloc(t->stts_entry_count
-               * sizeof(int32_t));
+       t->stts_sample_count = arr_alloc(t->stts_entry_count, sizeof(int32_t));
        for (uint32_t n = 0; n < t->stts_entry_count; n++) {
                ret = read_int32(f, &t->stts_sample_count[n]);
                if (ret <= 0)
@@ -284,9 +283,9 @@ static int read_stsc(struct mp4 *f)
        ret = read_int32(f, &t->stsc_entry_count);
        if (ret <= 0)
                return ret;
-       t->stsc_first_chunk = para_malloc(t->stsc_entry_count * sizeof(int32_t));
-       t->stsc_samples_per_chunk = para_malloc(t->stsc_entry_count
-               sizeof (int32_t));
+       t->stsc_first_chunk = arr_alloc(t->stsc_entry_count, sizeof(int32_t));
+       t->stsc_samples_per_chunk = arr_alloc(t->stsc_entry_count,
+               sizeof (int32_t));
        for (uint32_t n = 0; n < t->stsc_entry_count; n++) {
                ret = read_int32(f, &t->stsc_first_chunk[n]);
                if (ret <= 0)
@@ -310,8 +309,7 @@ static int read_stco(struct mp4 *f)
        ret = read_int32(f, &t->stco_entry_count);
        if (ret <= 0)
                return ret;
-       t->stco_chunk_offset = para_malloc(t->stco_entry_count
-               * sizeof(int32_t));
+       t->stco_chunk_offset = arr_alloc(t->stco_entry_count, sizeof(int32_t));
        for (uint32_t n = 0; n < t->stco_entry_count; n++) {
                ret = read_int32(f, &t->stco_chunk_offset[n]);
                if (ret <= 0)
@@ -396,7 +394,7 @@ static int parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
                        goto fail;
                len = subsize - (header_size + 8);
                free(value);
-               value = para_malloc(len + 1);
+               value = alloc(len + 1);
                ret = read_data(f, value, len);
                if (ret <= 0)
                        goto fail;
@@ -609,7 +607,7 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
        int ret;
        uint64_t size;
        uint8_t atom_type, header_size;
-       struct mp4 *f = para_calloc(sizeof(*f));
+       struct mp4 *f = zalloc(sizeof(*f));
 
        f->cb = cb;
        while ((ret = atom_read_header(f, &atom_type, &header_size, &size)) > 0) {
@@ -918,7 +916,7 @@ static void *modify_moov(struct mp4 *f, uint32_t *out_size)
                new_ilst_size += TAG_LEN(strlen(f->meta.tags[n].value));
        size_delta = new_ilst_size - (f->ilst_size - 8);
        *out_size = total_size + size_delta;
-       out_buffer = para_malloc(*out_size);
+       out_buffer = alloc(*out_size);
        p_out = out_buffer;
        set_position(f, total_base);
        ret = read_data(f, p_out, f->udta_offset - total_base);
diff --git a/net.c b/net.c
index 4a6f9a63cd8475f8e7a0f583be3ac7e3d205c1a7..e01af24be27c49a00a60a61a98448bc3d82046f0 100644 (file)
--- a/net.c
+++ b/net.c
@@ -286,7 +286,7 @@ struct flowopts {
  */
 struct flowopts *flowopt_new(void)
 {
-       struct flowopts *new = para_malloc(sizeof(*new));
+       struct flowopts *new = alloc(sizeof(*new));
 
        init_list_head(&new->sockopts);
        return new;
@@ -307,7 +307,7 @@ struct flowopts *flowopt_new(void)
 void flowopt_add(struct flowopts *fo, int lev, int opt,
                const char *name, const void *val, int len)
 {
-       struct pre_conn_opt *new = para_malloc(sizeof(*new));
+       struct pre_conn_opt *new = alloc(sizeof(*new));
 
        new->sock_option = opt;
        new->sock_level  = lev;
@@ -317,7 +317,7 @@ void flowopt_add(struct flowopts *fo, int lev, int opt,
                new->opt_val = NULL;
                new->opt_len = 0;
        } else {
-               new->opt_val = para_malloc(len);
+               new->opt_val = alloc(len);
                new->opt_len = len;
                memcpy(new->opt_val, val, len);
        }
index 3e36bdd5b1e9d3615695f975541bf69c0cc05093..3a5c263cbc09169f15c973040ddc2e0118b27c9c 100644 (file)
@@ -167,7 +167,7 @@ int oac_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
        PARA_INFO_LOG("%" PRIu32 " seconds, %d frames/chunk\n",
                afhi->seconds_total, frames_per_chunk);
        ct_size = 250;
-       afhi->chunk_table = para_malloc(ct_size * sizeof(uint32_t));
+       afhi->chunk_table = arr_alloc(ct_size, sizeof(uint32_t));
        afhi->chunk_table[0] = 0;
        afhi->chunk_table[1] = afhi->header_len;
        oss.returned = afhi->header_len;
@@ -179,9 +179,9 @@ int oac_get_file_info(char *map, size_t numbytes, struct afh_info *afhi,
                        j++;
                        if (j >= ct_size) {
                                ct_size *= 2;
-                               afhi->chunk_table = para_realloc(
+                               afhi->chunk_table = arr_realloc(
                                        afhi->chunk_table,
-                                       ct_size * sizeof(uint32_t));
+                                       ct_size, sizeof(uint32_t));
                        }
                        afhi->chunk_table[j] = oss.returned;
                }
@@ -367,7 +367,7 @@ struct oac_custom_header {
  */
 struct oac_custom_header *oac_custom_header_new(void)
 {
-       return para_calloc(sizeof(struct oac_custom_header));
+       return zalloc(sizeof(struct oac_custom_header));
 }
 
 /**
index a6fa056aa9bc354082542563b9d53864e01f390a..da70d4c04a2e2ec2dce8b955a5430442cd912519 100644 (file)
@@ -88,7 +88,7 @@ static const ov_callbacks ovc = {
 
 static void ogg_open(struct filter_node *fn)
 {
-       fn->private_data = para_calloc(sizeof(struct private_oggdec_data));
+       fn->private_data = zalloc(sizeof(struct private_oggdec_data));
        fn->min_iqs = 8000;
 }
 
@@ -121,7 +121,7 @@ static int ogg_init(struct filter_node *fn)
        struct btr_node *btrn = fn->btrn;
        int ret, oret;
        size_t iqs;
-       struct OggVorbis_File *vf = para_malloc(sizeof(*vf));
+       struct OggVorbis_File *vf = alloc(sizeof(*vf));
 
        PARA_NOTICE_LOG("iqs: %zu, min_iqs: %zu, opening ov callbacks\n",
                btr_get_input_queue_size(btrn), fn->min_iqs);
@@ -228,7 +228,7 @@ static int ogg_post_monitor(__a_unused struct sched *s, void *context)
                goto out;
        }
        have = 0;
-       buf = para_malloc(OGGDEC_OUTPUT_CHUNK_SIZE);
+       buf = alloc(OGGDEC_OUTPUT_CHUNK_SIZE);
        for (;;) {
                ret = ov_read(pod->vf, buf + have, OGGDEC_OUTPUT_CHUNK_SIZE - have,
                        ENDIAN, 2 /* 16 bit */, 1 /* signed */, NULL);
index 32891cbb012b66c0eaf5b8ca56f2c4288cd3bb1b..9d3ad577da4f5636f409fbacb0f1433ca0c720e1 100644 (file)
--- a/openssl.c
+++ b/openssl.c
@@ -283,7 +283,7 @@ int apc_get_pubkey(const char *key_file, struct asymmetric_key **result)
        unsigned char *blob;
        size_t decoded_size;
        int ret;
-       struct asymmetric_key *key = para_malloc(sizeof(*key));
+       struct asymmetric_key *key = alloc(sizeof(*key));
 
        ret = decode_public_key(key_file, &blob, &decoded_size);
        if (ret < 0)
@@ -324,7 +324,7 @@ int apc_priv_decrypt(const char *key_file, unsigned char *outbuf,
                return ret;
        if (inlen < 0)
                return -E_RSA;
-       priv = para_malloc(sizeof(*priv));
+       priv = alloc(sizeof(*priv));
        ret = get_private_key(key_file, &priv->rsa);
        if (ret < 0) {
                free(priv);
@@ -366,7 +366,7 @@ struct stream_cipher {
 
 struct stream_cipher *sc_new(const unsigned char *data, int len)
 {
-       struct stream_cipher *sc = para_malloc(sizeof(*sc));
+       struct stream_cipher *sc = alloc(sizeof(*sc));
 
        assert(len >= 2 * AES_CRT128_BLOCK_SIZE);
        sc->aes = EVP_CIPHER_CTX_new();
@@ -390,7 +390,7 @@ static void aes_ctr128_crypt(EVP_CIPHER_CTX *ctx, struct iovec *src,
 
        *dst = (typeof(*dst)) {
                /* Add one for the terminating zero byte. */
-               .iov_base = para_malloc(inlen + 1),
+               .iov_base = alloc(inlen + 1),
                .iov_len = inlen
        };
        ret = EVP_EncryptUpdate(ctx, dst->iov_base, &outlen, src->iov_base, inlen);
index dca6cfbad1ce3ff8cdf6d820b01bf33bf9a02110..0a291bb16c18b6705b70ff0260e97b502068f500 100644 (file)
@@ -179,7 +179,7 @@ static size_t opus_make_meta_packet(struct taginfo *tags, char **result)
        }
        PARA_DEBUG_LOG("meta packet size: %zu bytes\n", sz);
        /* terminating zero byte for the last sprintf() */
-       buf = p = para_malloc(sz + 1);
+       buf = p = alloc(sz + 1);
        memcpy(p, OPUS_COMMENT_HEADER, strlen(OPUS_COMMENT_HEADER));
        p += strlen(OPUS_COMMENT_HEADER);
        write_u32(p, comment_sz);
index 31f9640bbb915fc11ff1665c84fae0a61b902645..85287be0c813d4899b2f802735f2684338ea420c 100644 (file)
@@ -86,7 +86,7 @@ static int opusdec_execute(struct btr_node *btrn, const char *cmd,
 
 static void opusdec_open(struct filter_node *fn)
 {
-       struct opusdec_context *ctx = para_calloc(sizeof(*ctx));
+       struct opusdec_context *ctx = zalloc(sizeof(*ctx));
 
        ogg_sync_init(&ctx->oy);
        fn->private_data = ctx;
@@ -153,7 +153,7 @@ static void opusdec_add_output(short *pcm, int frames_available,
 
        if (tmp_skip > 0) {
                short *in = pcm + ctx->channels * tmp_skip;
-               short *out = para_malloc(bytes);
+               short *out = alloc(bytes);
                memcpy(out, in, bytes);
                free(pcm);
                pcm = out;
@@ -193,7 +193,7 @@ static int decode_packet(struct opusdec_context *ctx, ogg_packet *op,
        /* don't care for anything except opus eos */
        if (op->e_o_s && ctx->os.serialno == ctx->opus_serialno)
                ctx->eos = true;
-       output = para_malloc(sizeof(short) * MAX_FRAME_SIZE * ctx->channels);
+       output = arr_alloc(sizeof(short) * ctx->channels, MAX_FRAME_SIZE);
        ret = opus_multistream_decode(ctx->st, (unsigned char *)op->packet,
                op->bytes, output, MAX_FRAME_SIZE, 0);
        if (ret < 0) {
index f80301e9df282c13ef0e7d8ab2a025dd61624ba7..0814336fdc20fcebce15f344910c658726be831c 100644 (file)
--- a/oss_mix.c
+++ b/oss_mix.c
@@ -56,7 +56,7 @@ static int oss_mix_open(const char *dev, struct mixer_handle **handle)
                PARA_ERROR_LOG("could not open %s\n", dev);
                return ret;
        }
-       h = para_malloc(sizeof(*h));
+       h = alloc(sizeof(*h));
        h->fd = ret;
        *handle = h;
        return 1;
index 1a837e5700c7cfdb7e86951f8ae999645c49bd67..96d7b1871a941bff1662ae2a9512b85c79e7b4b9 100644 (file)
@@ -101,7 +101,7 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate,
 {
        int ret, format;
        unsigned ch, rate;
-       struct private_oss_write_data *powd = para_calloc(sizeof(*powd));
+       struct private_oss_write_data *powd = zalloc(sizeof(*powd));
        const char *dev = WRITE_CMD_OPT_STRING_VAL(OSS, DEVICE, wn->lpr);
 
        PARA_INFO_LOG("opening %s\n", dev);
diff --git a/para.h b/para.h
index 2525bee6e3a276da039790c0f39e056aed808f94..bbf91330855610ce0316986f2195d5161e3bc2bb 100644 (file)
--- a/para.h
+++ b/para.h
@@ -46,7 +46,6 @@
        typeof(x) _x = (x); \
        _x > 0? _x : -_x; })
 
-
 extern __printf_2_3 void (*para_log)(int, const char*, ...);
 /**
  * Define a standard log function that always writes to stderr.
diff --git a/play.c b/play.c
index 66383ebe0b8cb6a742801cfd33cd08155ee857b1..b60557244f5755b620c10240c60a2b73e28983e1 100644 (file)
--- a/play.c
+++ b/play.c
@@ -288,7 +288,7 @@ static int shuffle_compare(__a_unused const void *a, __a_unused const void *b)
 static void init_shuffle_map(void)
 {
        unsigned n, num_inputs = lls_num_inputs(play_lpr);
-       shuffle_map = para_malloc(num_inputs * sizeof(unsigned));
+       shuffle_map = arr_alloc(num_inputs, sizeof(unsigned));
        for (n = 0; n < num_inputs; n++)
                shuffle_map[n] = n;
        if (!OPT_GIVEN(RANDOMIZE))
@@ -591,7 +591,7 @@ static char *get_user_key_map_seq(int key)
        if (!p)
                return NULL;
        len = p - kma;
-       result = para_malloc(len + 1);
+       result = alloc(len + 1);
        memcpy(result, kma, len);
        result[len] = '\0';
        return result;
@@ -611,7 +611,7 @@ static char *get_key_map_seq_safe(int key)
 
        if (len == 1 && isprint(*seq))
                return seq;
-       sseq = para_malloc(2 + 2 * len + 1);
+       sseq = alloc(2 + 2 * len + 1);
        sseq[0] = '0';
        sseq[1] = 'x';
        for (n = 0; n < len; n++) {
@@ -651,7 +651,7 @@ static char **get_mapped_keyseqs(void)
        char **result;
        int i;
 
-       result = para_malloc((NUM_MAPPED_KEYS + 1) * sizeof(char *));
+       result = arr_alloc(NUM_MAPPED_KEYS + 1, sizeof(char *));
        FOR_EACH_MAPPED_KEY(i) {
                char *seq = get_key_map_seq(i);
                result[i] = seq;
@@ -1260,7 +1260,7 @@ int main(int argc, char *argv[])
        session_open();
        num_inputs = lls_num_inputs(play_lpr);
        init_shuffle_map();
-       pt->invalid = para_calloc(sizeof(*pt->invalid) * num_inputs);
+       pt->invalid = arr_zalloc(num_inputs, sizeof(*pt->invalid));
        pt->rq = CRT_FILE_CHANGE;
        pt->playing = true;
        pt->task = task_register(&(struct task_info){
index 031aa47e6c57efa0157a241a974c11af8bf64882..28b710108d435bd40d5970ca117b103d6fb0b1a3 100644 (file)
@@ -80,7 +80,7 @@ fail:
 
 static void prebuffer_open(struct filter_node *fn)
 {
-       struct private_prebuffer_data *ppd = para_calloc(sizeof(*ppd));
+       struct private_prebuffer_data *ppd = zalloc(sizeof(*ppd));
        fn->private_data = ppd;
 }
 
index ad34991c6a5b281aa6c39e392befa4fe64422335..1939300a7c946d68d1b324ee6beb8c0bf146893b 100644 (file)
@@ -41,7 +41,7 @@ int check_receiver_arg(const char *ra, struct lls_parse_result **lprp)
        *lprp = NULL;
        if (!ra || !*ra) {
                argc = 1;
-               argv = para_malloc(2 * sizeof(char*));
+               argv = alloc(2 * sizeof(char*));
                argv[0] = para_strdup("http");
                argv[1] = NULL;
        } else {
index 01b4ac48ce11b97d3199520a6e6f1342db87d470..bf28e975de2720f001be95ee06b269a1a8ecdd2c 100644 (file)
@@ -51,7 +51,7 @@ static void resample_close(struct filter_node *fn)
 
 static void resample_open(struct filter_node *fn)
 {
-       struct resample_context *ctx = para_calloc(sizeof(*ctx));
+       struct resample_context *ctx = zalloc(sizeof(*ctx));
        struct btr_node *btrn = fn->btrn;
        struct wav_params wp;
 
@@ -167,10 +167,10 @@ static int resample_frames(int16_t *in, size_t num_frames, bool have_more,
        data.output_frames = num_frames * ctx->ratio + 1;
        out_samples = data.output_frames * ctx->channels;
 
-       in_float = para_malloc(num_samples * sizeof(float));
+       in_float = arr_alloc(num_samples, sizeof(float));
        src_short_to_float_array(in, in_float, num_samples);
        data.data_in = in_float;
-       data.data_out = para_malloc(out_samples * sizeof(float));
+       data.data_out = arr_alloc(out_samples, sizeof(float));
        ret = src_process(ctx->src_state, &data);
        free(in_float);
        if (ret != 0) {
@@ -179,7 +179,7 @@ static int resample_frames(int16_t *in, size_t num_frames, bool have_more,
                return -E_LIBSAMPLERATE;
        }
        out_samples = data.output_frames_gen * ctx->channels;
-       out = para_malloc(out_samples * sizeof(short));
+       out = arr_alloc(out_samples, sizeof(short));
        src_float_to_short_array(data.data_out, out, out_samples);
        free(data.data_out);
        *result = out;
index 76e2d7afc8ab7caea1207a36c37c8b6452af2816..0e706f0f1ad6e906732f3bc95e8b653da53f9a6d 100644 (file)
@@ -41,8 +41,8 @@ struct ringbuffer
  */
 struct ringbuffer *ringbuffer_new(unsigned size)
 {
-       struct ringbuffer *rb = para_calloc(sizeof(struct ringbuffer));
-       rb->entries = para_calloc(size * sizeof(void *));
+       struct ringbuffer *rb = zalloc(sizeof(struct ringbuffer));
+       rb->entries = zalloc(size * sizeof(void *));
        rb->size = size;
        return rb;
 }
diff --git a/sched.c b/sched.c
index eb8d03c2bd99fdd1990d307aec977040c2611909..c786c9f26f9b5fc47cfd3c8d883671c5433bd048 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -230,7 +230,7 @@ void sched_shutdown(struct sched *s)
  */
 struct task *task_register(struct task_info *info, struct sched *s)
 {
-       struct task *t = para_malloc(sizeof(*t));
+       struct task *t = alloc(sizeof(*t));
 
        assert(info->post_monitor);
 
diff --git a/score.c b/score.c
index 894e8ca3deae39f21552a6cd331237551e9c7a1b..54af56f7c60100ad65ac09cafb52e7769514c958 100644 (file)
--- a/score.c
+++ b/score.c
@@ -119,7 +119,7 @@ int score_add(const struct osl_row *aft_row, long score)
        score_objs[SCORECOL_AFT_ROW].size = size;
 
        size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
-       score_objs[SCORECOL_SCORE].data = para_malloc(size);
+       score_objs[SCORECOL_SCORE].data = alloc(size);
        score_objs[SCORECOL_SCORE].size = size;
        *(long *)(score_objs[SCORECOL_SCORE].data) = score;
 
@@ -176,7 +176,7 @@ int score_update(const struct osl_row *aft_row, long percent)
                return ret;
        new_score--;
        obj.size = sizeof(long);
-       obj.data = para_malloc(obj.size);
+       obj.data = alloc(obj.size);
        *(long *)obj.data = new_score;
        PARA_DEBUG_LOG("new score: %ld, rank %u/%u\n", new_score, new_pos, n);
        return osl(osl_update_object(score_table, row, SCORECOL_SCORE, &obj));
index ce167542c8c3178986037c806d88af6b0c4623f2..26502cabd08376673b2c46b61ccffae400344274 100644 (file)
@@ -120,14 +120,14 @@ void init_sender_status(struct sender_status *ss,
 
        if (n == 0) {
                ss->num_listen_fds = 1;
-               ss->listen_addresses = para_malloc(sizeof(char *));
+               ss->listen_addresses = alloc(sizeof(char *));
                ss->listen_addresses[0] = NULL;
-               ss->listen_fds = para_malloc(sizeof(int));
+               ss->listen_fds = alloc(sizeof(int));
                ss->listen_fds[0] = -1;
        } else {
                ss->num_listen_fds = n;
-               ss->listen_addresses = para_malloc(n * sizeof(char *));
-               ss->listen_fds = para_malloc(n * sizeof(int));
+               ss->listen_addresses = alloc(n * sizeof(char *));
+               ss->listen_fds = alloc(n * sizeof(int));
                FOR_EACH_LISTEN_FD(i, ss) {
                        ss->listen_addresses[i] = para_strdup(lls_string_val(i,
                                listen_address_opt_result));
@@ -390,7 +390,7 @@ struct sender_client *accept_sender_client(struct sender_status *ss)
                if (ret < 0)
                        goto close_fd_and_warn;
                ss->num_clients++;
-               sc = para_calloc(sizeof(*sc));
+               sc = zalloc(sizeof(*sc));
                sc->fd = fd;
                sc->name = para_strdup(remote_name(fd));
                sc->cq = cq_new(MAX_CQ_BYTES);
index 2852ee1f10f7a9d8d4f5a93e2233b8b6fd4a4ecc..ea9cc9c003616762a96aa546c381d54417fd34a2 100644 (file)
--- a/server.c
+++ b/server.c
@@ -436,14 +436,14 @@ static void init_server_command_task(struct server_command_task *sct,
        sct->argv = argv;
        if (!OPT_GIVEN(LISTEN_ADDRESS)) {
                sct->num_listen_fds = 1;
-               sct->listen_fds = para_malloc(sizeof(int));
+               sct->listen_fds = alloc(sizeof(int));
                ret = para_listen_simple(IPPROTO_TCP, port);
                if (ret < 0)
                        goto err;
                sct->listen_fds[0] = ret;
        } else {
                sct->num_listen_fds = OPT_GIVEN(LISTEN_ADDRESS);
-               sct->listen_fds = para_malloc(sct->num_listen_fds * sizeof(int));
+               sct->listen_fds = alloc(sct->num_listen_fds * sizeof(int));
                for (n = 0; n < OPT_GIVEN(LISTEN_ADDRESS); n++) {
                        const char *arg;
                        arg = lls_string_val(n, OPT_RESULT(LISTEN_ADDRESS));
index ed7867a1c37027d7a49d1047bd349c5976d0e8d7..d4876234a192a956f112c48f871ed1fb0d5321b7 100644 (file)
@@ -37,7 +37,7 @@ struct sb_context {
 struct sb_context *sb_new_recv(size_t max_size, sb_transformation t,
                void *trafo_context)
 {
-       struct sb_context *c = para_calloc(sizeof(*c));
+       struct sb_context *c = zalloc(sizeof(*c));
 
        c->max_size = max_size;
        c->trafo = t;
@@ -62,7 +62,7 @@ struct sb_context *sb_new_recv(size_t max_size, sb_transformation t,
 struct sb_context *sb_new_send(struct sb_buffer *sbb, bool dont_free,
                sb_transformation t, void *trafo_context)
 {
-       struct sb_context *c = para_calloc(sizeof(*c));
+       struct sb_context *c = zalloc(sizeof(*c));
        struct iovec src, dst, *srcp, *dstp;
 
        assert(sbb);
@@ -266,7 +266,7 @@ int sb_received(struct sb_context *c, size_t nbytes, struct sb_buffer *result)
         */
        if (sbb->iov.iov_len == (size_t)-1)
                return -E_SB_PACKET_SIZE;
-       sbb->iov.iov_base = para_malloc(sbb->iov.iov_len + 1);
+       sbb->iov.iov_base = alloc(sbb->iov.iov_len + 1);
        return 0; /* ready to read body */
 success:
        *result = c->sbb;
index e5ef7a4119dc271320079d778313c5abf1d259d2..bdafeaf296e026508698c306e4b498e0710a9cee 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -48,7 +48,7 @@ struct signal_task *signal_init_or_die(void)
        ret = mark_fd_nonblocking(signal_pipe[1]);
        if (ret < 0)
                goto err_out;
-       st = para_calloc(sizeof(*st));
+       st = zalloc(sizeof(*st));
        st->fd = signal_pipe[0];
        return st;
 err_out:
index caeacb1921341b04b26f117d5de6607a80ab95e9..cd3b7cde907388465f04ead39af10bd125d154ca 100644 (file)
--- a/spx_afh.c
+++ b/spx_afh.c
@@ -195,7 +195,7 @@ static size_t spx_make_meta_packet(struct taginfo *tags, char **result)
        }
        PARA_DEBUG_LOG("meta packet size: %zu bytes\n", sz);
        /* terminating zero byte for the last sprintf() */
-       buf = p = para_malloc(sz + 1);
+       buf = p = alloc(sz + 1);
        write_u32(p, comment_sz);
        p += 4;
        strcpy(p, tags->comment);
index 94a9c78835e93157be51753bc910f251820501e8..08eac02a557b2d503646666edd7ffb35e1c5c5f7 100644 (file)
@@ -81,7 +81,7 @@ struct private_spxdec_data {
 
 static void spxdec_open(struct filter_node *fn)
 {
-       struct private_spxdec_data *psd = para_calloc(sizeof(*psd));
+       struct private_spxdec_data *psd = zalloc(sizeof(*psd));
 
        fn->private_data = psd;
        fn->min_iqs = 200;
@@ -171,7 +171,7 @@ static int speexdec_write_frames(int packet_no,
                if (new_frame_size <= 0)
                        continue;
                samples = new_frame_size * psd->shi.channels;
-               btr_output = para_malloc(2 * samples);
+               btr_output = arr_alloc(samples, 2);
                for (i = 0; i < samples; i++)
                        btr_output[i] = read_u16(output + i + skip_idx);
                btr_add_output((char *)btr_output, samples * 2, btrn);
index 0e04d3740b499b3db6721690d3c30419758b8371..2c6d35d60e7c69900826f8ddbbd7b1e16fb8cbd4 100644 (file)
--- a/string.c
+++ b/string.c
 #include "error.h"
 
 /**
- * Paraslash's version of realloc().
+ * Reallocate an array, abort on failure or bugs.
  *
- * \param p Pointer to the memory block, may be \p NULL.
- * \param size The desired new size.
+ * \param ptr Pointer to the memory block, may be NULL.
+ * \param nmemb Number of elements.
+ * \param size The size of one element in bytes.
  *
- * A wrapper for realloc(3). It calls \p exit(\p EXIT_FAILURE) on errors,
- * i.e. there is no need to check the return value in the caller.
+ * A wrapper for realloc(3) which aborts on invalid arguments or integer
+ * overflow. The wrapper also terminates the current process on allocation
+ * errors, so the caller does not need to check for failure.
  *
  * \return A pointer to newly allocated memory which is suitably aligned for
- * any kind of variable and may be different from \a p.
+ * any kind of variable and may be different from ptr.
  *
  * \sa realloc(3).
  */
-__must_check void *para_realloc(void *p, size_t size)
+__must_check void *arr_realloc(void *ptr, size_t nmemb, size_t size)
+{
+       size_t pr;
+
+       assert(size > 0);
+       assert(nmemb > 0);
+       assert(!__builtin_mul_overflow(nmemb, size, &pr));
+       assert(pr != 0);
+       ptr = realloc(ptr, pr);
+       assert(ptr);
+       return ptr;
+}
+
+/**
+ * Allocate an array, abort on failure or bugs.
+ *
+ * \param nmemb See \ref arr_realloc().
+ * \param size See \ref arr_realloc().
+ *
+ * Like \ref arr_realloc(), this aborts on invalid arguments, integer overflow
+ * and allocation errors.
+ *
+ * \return A pointer to newly allocated memory which is suitably aligned for
+ * any kind of variable.
+ *
+ * \sa See \ref arr_realloc().
+ */
+__must_check __malloc void *arr_alloc(size_t nmemb, size_t size)
+{
+       return arr_realloc(NULL, nmemb, size);
+}
+
+/**
+ * Allocate and initialize an array, abort on failure or bugs.
+ *
+ * \param nmemb See \ref arr_realloc().
+ * \param size See \ref arr_realloc().
+ *
+ * This calls \ref arr_alloc() and zeroes-out the array.
+ *
+ * \return See \ref arr_alloc().
+ */
+__must_check __malloc void *arr_zalloc(size_t nmemb, size_t size)
 {
+       void *ptr = arr_alloc(nmemb, size);
+
        /*
-        * No need to check for NULL pointers: If p is NULL, the call
-        * to realloc is equivalent to malloc(size)
+        * This multiplication can not overflow because the above call to \ref
+        * arr_alloc() aborts on overflow.
         */
-       assert(size);
-       if (!(p = realloc(p, size))) {
-               PARA_EMERG_LOG("realloc failed (size = %zu), aborting\n",
-                       size);
-               exit(EXIT_FAILURE);
-       }
-       return p;
+       memset(ptr, 0, nmemb * size);
+       return ptr;
 }
 
 /**
- * Paraslash's version of malloc().
+ * Allocate and initialize memory.
  *
  * \param size The desired new size.
  *
- * A wrapper for malloc(3) which exits on errors.
- *
- * \return A pointer to the allocated memory, which is suitably aligned for any
- * kind of variable.
+ * \return A pointer to the allocated and zeroed-out memory, which is suitably
+ * aligned for any kind of variable.
  *
- * \sa malloc(3).
+ * \sa \ref alloc(), calloc(3).
  */
-__must_check __malloc void *para_malloc(size_t size)
+__must_check void *zalloc(size_t size)
 {
-       void *p;
-
-       assert(size);
-       p = malloc(size);
-       if (!p) {
-               PARA_EMERG_LOG("malloc failed (size = %zu), aborting\n",
-                       size);
-               exit(EXIT_FAILURE);
-       }
-       return p;
+       return arr_zalloc(1, size);
 }
 
 /**
- * Paraslash's version of calloc().
+ * Paraslash's version of realloc().
  *
+ * \param p Pointer to the memory block, may be \p NULL.
  * \param size The desired new size.
  *
- * A wrapper for calloc(3) which exits on errors.
+ * A wrapper for realloc(3). It calls \p exit(\p EXIT_FAILURE) on errors,
+ * i.e. there is no need to check the return value in the caller.
  *
- * \return A pointer to the allocated and zeroed-out memory, which is suitably
- * aligned for any kind of variable.
+ * \return A pointer to newly allocated memory which is suitably aligned for
+ * any kind of variable and may be different from \a p.
  *
- * \sa calloc(3)
+ * \sa realloc(3).
  */
-__must_check __malloc void *para_calloc(size_t size)
+__must_check void *para_realloc(void *p, size_t size)
 {
-       void *ret = para_malloc(size);
+       return arr_realloc(p, 1, size);
+}
 
-       memset(ret, 0, size);
-       return ret;
+/**
+ * Paraslash's version of malloc().
+ *
+ * \param size The desired new size.
+ *
+ * A wrapper for malloc(3) which exits on errors.
+ *
+ * \return A pointer to the allocated memory, which is suitably aligned for any
+ * kind of variable.
+ *
+ * \sa malloc(3).
+ */
+__must_check __malloc void *alloc(size_t size)
+{
+       return arr_alloc(1, size);
 }
 
 /**
@@ -94,22 +140,23 @@ __must_check __malloc void *para_calloc(size_t size)
  *
  * \param s The string to be duplicated.
  *
- * A wrapper for strdup(3). It calls \p exit(EXIT_FAILURE) on errors, i.e.
- * there is no need to check the return value in the caller.
+ * A strdup(3)-like function which aborts if insufficient memory was available
+ * to allocate the duplicated string, absolving the caller from the
+ * responsibility to check for failure.
  *
- * \return A pointer to the duplicated string. If \a s was the \p NULL pointer,
- * an pointer to an empty string is returned.
+ * \return A pointer to the duplicated string. Unlike strdup(3), the caller may
+ * pass NULL, in which case the function returns a pointer to an empty string.
+ * Regardless of whether or not NULL was passed, the returned string is
+ * allocated on the heap and has to be freed by the caller.
  *
- * \sa strdup(3)
+ * \sa strdup(3).
  */
 __must_check __malloc char *para_strdup(const char *s)
 {
-       char *ret;
+       char *dupped_string = strdup(s? s: "");
 
-       if ((ret = strdup(s? s: "")))
-               return ret;
-       PARA_EMERG_LOG("strdup failed, aborting\n");
-       exit(EXIT_FAILURE);
+       assert(dupped_string);
+       return dupped_string;
 }
 
 /**
@@ -137,7 +184,7 @@ __printf_2_0 unsigned xvasprintf(char **result, const char *fmt, va_list ap)
        size_t size = 150;
        va_list aq;
 
-       *result = para_malloc(size + 1);
+       *result = alloc(size + 1);
        va_copy(aq, ap);
        ret = vsnprintf(*result, size, fmt, aq);
        va_end(aq);
@@ -339,7 +386,7 @@ int for_each_line(unsigned flags, char *buf, size_t size,
                if (!(flags & FELF_DISCARD_FIRST) || start != buf) {
                        if (flags & FELF_READ_ONLY) {
                                size_t s = end - start;
-                               char *b = para_malloc(s + 1);
+                               char *b = alloc(s + 1);
                                memcpy(b, start, s);
                                b[s] = '\0';
                                ret = line_handler(b, private_data);
@@ -443,7 +490,7 @@ __printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...)
        int ret, sz_off = (b->flags & PBF_SIZE_PREFIX)? 5 : 0;
 
        if (!b->buf) {
-               b->buf = para_malloc(128);
+               b->buf = alloc(128);
                b->size = 128;
                b->offset = 0;
        }
@@ -560,7 +607,7 @@ static int get_next_word(const char *buf, const char *delim, char **word)
        char *out;
        int ret, state = 0;
 
-       out = para_malloc(strlen(buf) + 1);
+       out = alloc(strlen(buf) + 1);
        *out = '\0';
        *word = out;
        for (in = buf; *in; in++) {
@@ -692,7 +739,7 @@ void free_argv(char **argv)
 static int create_argv_offset(int offset, const char *buf, const char *delim,
                char ***result)
 {
-       char *word, **argv = para_malloc((offset + 1) * sizeof(char *));
+       char *word, **argv = arr_alloc(offset + 1, sizeof(char *));
        const char *p;
        int i, ret;
 
@@ -704,7 +751,7 @@ static int create_argv_offset(int offset, const char *buf, const char *delim,
                        goto err;
                if (!ret)
                        break;
-               argv = para_realloc(argv, (i + 2) * sizeof(char*));
+               argv = arr_realloc(argv, i + 2, sizeof(char*));
                argv[i] = word;
        }
        argv[i] = NULL;
@@ -800,7 +847,7 @@ int para_regcomp(regex_t *preg, const char *regex, int cflags)
        if (ret == 0)
                return 1;
        size = regerror(ret, preg, NULL, 0);
-       buf = para_malloc(size);
+       buf = alloc(size);
        regerror(ret, preg, buf, size);
        PARA_ERROR_LOG("%s\n", buf);
        free(buf);
@@ -826,7 +873,7 @@ char *safe_strdup(const char *src, size_t len)
        char *p;
 
        assert(len < (size_t)-1);
-       p = para_malloc(len + 1);
+       p = alloc(len + 1);
        if (len > 0)
                memcpy(p, src, len);
        p[len] = '\0';
@@ -980,7 +1027,7 @@ __must_check int strwidth(const char *s, size_t *result)
                return -ERRNO_TO_PARA_ERROR(errno);
        if (num_wchars == 0)
                return 0;
-       dest = para_malloc((num_wchars + 1) * sizeof(*dest));
+       dest = arr_alloc(num_wchars + 1, sizeof(*dest));
        src = s;
        memset(&state, 0, sizeof(state));
        num_wchars = mbsrtowcs(dest, &src, num_wchars, &state);
@@ -1035,7 +1082,7 @@ __must_check int sanitize_str(const char *src, size_t max_width,
        num_wchars = mbsrtowcs(NULL, &src, 0, &state);
        if (num_wchars == (size_t)-1)
                return -ERRNO_TO_PARA_ERROR(errno);
-       wcs = para_malloc((num_wchars + 1) * sizeof(*wcs));
+       wcs = arr_alloc(num_wchars + 1, sizeof(*wcs));
        memset(&state, 0, sizeof(state));
        num_wchars = mbsrtowcs(wcs, &src, num_wchars + 1, &state);
        assert(num_wchars != (size_t)-1);
@@ -1046,7 +1093,7 @@ __must_check int sanitize_str(const char *src, size_t max_width,
        }
        wcs[n] = L'\0';
        n = wcstombs(NULL, wcs, 0) + 1;
-       *result = para_malloc(n);
+       *result = alloc(n);
        num_wchars = wcstombs(*result, wcs, n);
        assert(num_wchars != (size_t)-1);
        free(wcs);
index 84b6f787924f18a805eea6b5d2730a4ffa230159..060d65403bc5b0294010b582032eb5ed8ab10d49 100644 (file)
--- a/string.h
+++ b/string.h
@@ -67,9 +67,12 @@ int for_each_line(unsigned flags, char *buf, size_t size,
 } \
 )
 
+__must_check void *arr_realloc(void *ptr, size_t nmemb, size_t size);
 __must_check void *para_realloc(void *p, size_t size);
-__must_check __malloc void *para_malloc(size_t size);
-__must_check __malloc void *para_calloc(size_t size);
+__must_check __malloc void *alloc(size_t size);
+__must_check __malloc void *zalloc(size_t size);
+__must_check __malloc void *arr_alloc(size_t nmemb, size_t size);
+__must_check __malloc void *arr_zalloc(size_t nmemb, size_t size);
 __must_check __malloc char *para_strdup(const char *s);
 
 __printf_2_0 unsigned xvasprintf(char **result, const char *fmt, va_list ap);
index 3174a4ef741b0afe1107ff6bd9146f1c82f5f77e..b4710f6704ce7a4fbd03567d806ce633df164008 100644 (file)
@@ -102,7 +102,7 @@ static void sync_open(struct filter_node *fn)
        unsigned buddy_given;
        const struct lls_opt_result *r_b;
 
-       ctx = fn->private_data = para_calloc(sizeof(*ctx));
+       ctx = fn->private_data = zalloc(sizeof(*ctx));
        init_list_head(&ctx->buddies);
 
        /* create socket to listen for incoming packets */
@@ -148,7 +148,7 @@ static void sync_open(struct filter_node *fn)
                        close(fd);
                        goto fail;
                }
-               buddy = para_malloc(sizeof(*buddy));
+               buddy = alloc(sizeof(*buddy));
                buddy->fd = fd;
                buddy->sbi = sbi + i;
                buddy->ping_received = false;
@@ -176,12 +176,12 @@ static void *sync_setup(const struct lls_parse_result *lpr)
 
        r_b = FILTER_CMD_OPT_RESULT(SYNC, BUDDY, lpr);
        n = lls_opt_given(r_b);
-       sbi = para_malloc(n * sizeof(*sbi));
+       sbi = arr_alloc(n, sizeof(*sbi));
        PARA_INFO_LOG("initializing buddy info array of length %u\n", n);
        for (i = 0; i < n; i++) {
                const char *url = lls_string_val(i, r_b);
                size_t len = strlen(url);
-               char *host = para_malloc(len + 1);
+               char *host = alloc(len + 1);
                int port;
                struct addrinfo *ai;
 
index ac656ff2cc02a47353fb73231fa96ad517dcd090..289479878592f6b50e5e31bb30a1098e71588865 100644 (file)
@@ -326,8 +326,8 @@ static int udp_com_add(struct sender_command_data *scd)
                                sc->name);
                return -E_TARGET_EXISTS;
        }
-       ut = para_calloc(sizeof(*ut));
-       sc = para_calloc(sizeof(*sc));
+       ut = zalloc(sizeof(*ut));
+       sc = zalloc(sizeof(*sc));
        ut->fcp.slices_per_group      = scd->slices_per_group;
        ut->fcp.data_slices_per_group = scd->data_slices_per_group;
        ut->fcp.init_fec              = udp_init_fec;
index 32a4309d4360fa73a8e7d0bbef622a7928001bb0..f2436c9e5bf7a835db2553c4c54db112d628b40d 100644 (file)
@@ -110,7 +110,7 @@ void user_list_init(const char *user_list_file)
                        apc_free_pubkey(pubkey);
                        continue;
                }
-               u = para_malloc(sizeof(*u));
+               u = alloc(sizeof(*u));
                u->name = para_strdup(n);
                u->pubkey = pubkey;
                u->perms = 0;
diff --git a/vss.c b/vss.c
index 4f270c4a50b35df749c8f9c3cf2bbeba9464eb7b..dd4ac2fbc96f54064f0dacd38ef2c9c39fa4f065 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -335,10 +335,10 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst)
        ret = fec_new(k, n, &fc->parms);
        if (ret < 0)
                return ret;
-       fc->src_data = para_malloc(k * sizeof(char *));
+       fc->src_data = arr_alloc(k, sizeof(char *));
        for (i = 0; i < k; i++)
-               fc->src_data[i] = para_malloc(fc->mps);
-       fc->enc_buf = para_malloc(fc->mps);
+               fc->src_data[i] = alloc(fc->mps);
+       fc->enc_buf = alloc(fc->mps);
 
        fc->state = FEC_STATE_READY_TO_RUN;
        fc->next_header_time.tv_sec = 0;
@@ -671,7 +671,7 @@ size_t vss_get_fec_eof_packet(const char **buf)
 struct fec_client *vss_add_fec_client(struct sender_client *sc,
                                      struct fec_client_parms *fcp)
 {
-       struct fec_client *fc = para_calloc(sizeof(*fc));
+       struct fec_client *fc = zalloc(sizeof(*fc));
 
        fc->sc  = sc;
        fc->fcp = fcp;
index 692306b541fcb28012b1a2a4d873a83d93855437..7d6c371433b13ae6f6d3d63e8de47f69fe133a17 100644 (file)
@@ -53,7 +53,7 @@ static void wav_open(struct filter_node *fn)
 {
        int *bof;
 
-       fn->private_data = para_malloc(sizeof(int));
+       fn->private_data = alloc(sizeof(int));
        bof = fn->private_data;
        *bof = 1;
 }
@@ -101,7 +101,7 @@ static int wav_post_monitor(__a_unused struct sched *s, void *context)
        free(buf);
        if (ret < 0)
                goto err;
-       header = para_malloc(WAV_HEADER_LEN);
+       header = alloc(WAV_HEADER_LEN);
        make_wav_header(ch, rate, header);
        btr_add_output(header, WAV_HEADER_LEN, btrn);
        ret = -E_WAV_SUCCESS;
index 78834a4d48be70f178dba5ffed88f5db8761745c..b5329ea07f3d8a2f9553f384c9129c4ad1a262e3 100644 (file)
@@ -309,8 +309,8 @@ repository with
                git clone git://git.tuebingen.mpg.de/lopsub
 
 - [gcc](ftp://ftp.gnu.org/pub/gnu/gcc) or
-[clang](http://clang.llvm.org). All gcc versions >= 4.2 are currently
-supported. Clang version 1.1 or newer should work as well.
+[clang](http://clang.llvm.org). All gcc versions >= 5.4 are currently
+supported. Moderately recent versions of clang should work as well.
 
 - [gnu make](ftp://ftp.gnu.org/pub/gnu/make) is also shipped with the
 disto. On BSD systems the gnu make executable is often called gmake.
index 63e49677b0f1b85c13c17160a7b249531c1fbcd4..8bff7cfcaa98f8ae3bdfb00f87545c70c7927d94 100644 (file)
--- a/wma_afh.c
+++ b/wma_afh.c
@@ -195,7 +195,7 @@ static int wma_make_chunk_table(char *buf, size_t buf_size, uint32_t packet_size
        size_t ct_size = 250;
        int ret, count = 0, num_frames, num_superframes;
 
-       afhi->chunk_table = para_malloc(ct_size * sizeof(uint32_t));
+       afhi->chunk_table = arr_alloc(ct_size, sizeof(uint32_t));
        afhi->chunk_table[0] = 0;
        afhi->chunk_table[1] = afhi->header_len;
 
@@ -318,7 +318,7 @@ static int convert_utf8_to_utf16(char *src, char **dst)
        int ret;
 
        if (!src || !*src) {
-               *dst = para_calloc(2);
+               *dst = zalloc(2);
                return 0;
        }
        /*
@@ -334,7 +334,7 @@ static int convert_utf8_to_utf16(char *src, char **dst)
        /* even though src is in UTF-8, strlen() should DTRT */
        inbytes = inbytesleft = strlen(src);
        outbytes = outbytesleft = 4 * inbytes + 2; /* hope that's enough */
-       *dst = outbuf = para_malloc(outbytes);
+       *dst = outbuf = alloc(outbytes);
        sz = iconv(cd, ICONV_CAST &inbuf, &inbytesleft, &outbuf, &outbytesleft);
        if (sz == (size_t)-1) {
                ret = -ERRNO_TO_PARA_ERROR(errno);
@@ -411,7 +411,7 @@ static int make_cdo(struct taginfo *tags, const struct asf_object *cdo,
        result->size = 16 + 8 + 5 * 2 + title_bytes + artist_bytes
                + orig_cr_bytes + comment_bytes + orig_rating_bytes;
        PARA_DEBUG_LOG("cdo is %zu bytes\n", (size_t)result->size);
-       p = result->ptr = para_malloc(result->size);
+       p = result->ptr = alloc(result->size);
        memcpy(p, content_description_header, 16);
        p += 16;
        write_u64(p, result->size);
@@ -469,7 +469,7 @@ static int make_ecdo(struct taginfo *tags, struct asf_object *result)
        result->size += 2 + sizeof(album_tag_header) + 2 + 2 + 2 + album_bytes;
        result->size += 2 + sizeof(year_tag_header) + 2 + 2 + 2 + year_bytes;
 
-       p = result->ptr = para_malloc(result->size);
+       p = result->ptr = alloc(result->size);
        memcpy(p, extended_content_header, 16);
        p += 16;
        write_u64(p, result->size);
@@ -622,7 +622,7 @@ static int wma_rewrite_tags(const char *map, size_t mapsize,
        if (top.reserved2 != 2)
                return -E_NO_WMA;
        p++; /* objects start at p */
-       top.objects = para_malloc(top.num_objects * sizeof(struct asf_object));
+       top.objects = arr_alloc(top.num_objects, sizeof(struct asf_object));
        ret = read_asf_objects(p, top.size - (p - map), top.num_objects,
                top.objects, &ton);
        if (ret < 0)
index 8061f9aeedb32d6cd0b0cf2083eefd991ed8a1d8..f7ee2c4dbd1281e49792693afd40e83f275cd919 100644 (file)
@@ -159,8 +159,8 @@ static void init_coef_vlc(struct private_wmadec_data *pwd, int sidx, int didx)
        int i, l, j, k, level, n = src->n;
 
        init_vlc(dst, VLCBITS, n, src->huffbits, src->huffcodes, 4);
-       pwd->run_table[didx] = para_malloc(n * sizeof(uint16_t));
-       pwd->level_table[didx] = para_malloc(n * sizeof(uint16_t));
+       pwd->run_table[didx] = arr_alloc(n, sizeof(uint16_t));
+       pwd->level_table[didx] = arr_alloc(n, sizeof(uint16_t));
        i = 2;
        level = 1;
        k = 0;
@@ -427,7 +427,7 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat
        int ret, i;
 
        PARA_NOTICE_LOG("initial buf: %d bytes\n", len);
-       pwd = para_calloc(sizeof(*pwd));
+       pwd = zalloc(sizeof(*pwd));
        ret = read_asf_header(initial_buf, len, &pwd->ahi);
        if (ret <= 0) {
                free(pwd);
@@ -1196,7 +1196,7 @@ next_buffer:
        if (fn->min_iqs > len)
                goto success;
        out_size = WMA_OUTPUT_BUFFER_SIZE;
-       out = para_malloc(out_size);
+       out = alloc(out_size);
        ret = wma_decode_superframe(pwd, out, &out_size,
                (uint8_t *)in + WMA_FRAME_SKIP);
        if (ret < 0) {
diff --git a/write.c b/write.c
index 9e2de3d8207d977d074546280304db085990e761..f7018aa115a632f345f5136c734f44e2b79d87a5 100644 (file)
--- a/write.c
+++ b/write.c
@@ -89,7 +89,7 @@ static int setup_and_schedule(struct lls_parse_result *lpr)
        }, &s);
 
        n = writer_given? writer_given : 1;
-       wns = para_calloc(n * sizeof(*wns));
+       wns = arr_zalloc(n, sizeof(*wns));
        for (i = 0; i < n; i++) {
                const char *arg = i < writer_given?
                        lls_string_val(i, OPT_RESULT(WRITER, lpr)) : NULL;
index 806d682f7a4b914e019fe152945e13a0d623cd76..9a13090541895df5b7bc7ee8f42fbc2fda37a9f2 100644 (file)
@@ -85,7 +85,7 @@ int check_writer_arg_or_die(const char *wa, struct lls_parse_result **lprp)
        if (!wa || !*wa) {
                writer_num = default_writer_id();
                cmd = WRITE_CMD(writer_num);
-               argv = para_malloc(2 * sizeof(char *));
+               argv = alloc(2 * sizeof(char *));
                argc = 1;
                argv[0] = para_strdup(lls_command_name(cmd));
                argv[1] = NULL;
diff --git a/yy/mp.y b/yy/mp.y
index 06d76101daf42550ea192d1c963c32d5da6635d2..8df4f20ea04ebd2ea23b77ad77451e23e0022dbc 100644 (file)
--- a/yy/mp.y
+++ b/yy/mp.y
@@ -59,7 +59,7 @@ enum semantic_types {
 
 static struct mp_ast_node *ast_node_raw(int id)
 {
-       struct mp_ast_node *node = para_malloc(sizeof(struct mp_ast_node));
+       struct mp_ast_node *node = alloc(sizeof(struct mp_ast_node));
        node->id = id;
        return node;
 }
@@ -76,7 +76,7 @@ static struct mp_ast_node *ast_node_new_unary(int id, struct mp_ast_node *child)
 {
        struct mp_ast_node *node = ast_node_raw(id);
        node->num_children = 1;
-       node->children = para_malloc(sizeof(struct mp_ast_node *));
+       node->children = alloc(sizeof(struct mp_ast_node *));
        node->children[0] = child;
        return node;
 }
@@ -86,7 +86,7 @@ static struct mp_ast_node *ast_node_new_binary(int id, struct mp_ast_node *left,
 {
        struct mp_ast_node *node = ast_node_raw(id);
        node->num_children = 2;
-       node->children = para_malloc(2 * sizeof(struct mp_ast_node *));
+       node->children = arr_alloc(2, sizeof(struct mp_ast_node *));
        node->children[0] = left;
        node->children[1] = right;
        return node;