]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'refs/heads/t/format-signedness'
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 28 Dec 2016 19:38:34 +0000 (20:38 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 28 Dec 2016 19:42:12 +0000 (20:42 +0100)
This series fixes all warnings produced by compiling with
-Wformat-signedness and adds the flag to CFLAGS if the compiler
supports it.

* refs/heads/t/format-signedness (cooking for ~2 weeks):
  gcrypt: Fix a few format-signedness issues.
  Compile with -Wformat-signedness if possible.
  Fix signedness issues in format strings.

13 files changed:
1  2 
NEWS.md
aac_afh.c
aac_common.c
aacdec_filter.c
afs.c
aft.c
crypt_common.c
fade.c
gcrypt.c
play.c
server.c
wma_common.c
wmadec_filter.c

diff --combined NEWS.md
index 10e78ca542c556ad5406f7920672c6f0dbb66cf0,71eb6cb26d3a333f8840f78848ad74986f689754..a7af771744e91e3654bd216b217f40a56eae11ea
+++ b/NEWS.md
@@@ -1,22 -1,6 +1,23 @@@
  NEWS
  ====
  
 +------------------------------------------
 +0.5.7 (to be announced) "semantic density"
 +------------------------------------------
 +- Speedup of the base64 decoder.
 +- One of the two source browsers has been removed from the web pages.
 +  The doxygen API reference still contains an HTML version of each
 +  source file.
 +- Two race conditions in para_server have been fixed.
 +- ls -p is now deprecated in favor of -F or -b. See the help text of
 +  the ls command for details.
 +- The openssl code has been adjusted to work also with openssl-1.1.
 +- The wma decoder and audio format handler now correctly decodes
 +  files with unusual block sizes.
++- We now compile with -Wformat-signedness if possible.
 +
 +Download: [tarball](./releases/paraslash-git.tar.bz2)
 +
  ---------------------------------------
  0.5.6 (2016-07-10) "cascading gradient"
  ---------------------------------------
diff --combined aac_afh.c
index a30be96f4f9da70b841e26fd16a3044ebc1df8ac,bcd2a14edfd8de64baaca165f17ae855490e8cc9..1c7fd706f0a7c9fe8c9d4d8db43846be18a9304d
+++ b/aac_afh.c
  
  #include "para.h"
  #include "error.h"
 +#include "portable_io.h"
  #include "afh.h"
  #include "string.h"
  #include "aac.h"
  #include "fd.h"
  
 -static int aac_find_stsz(unsigned char *buf, size_t buflen, off_t *skip)
 +static int aac_find_stsz(char *buf, size_t buflen, off_t *skip)
  {
        int i;
  
        for (i = 0; i + 16 < buflen; i++) {
 -              unsigned char *p = buf + i;
 +              char *p = buf + i;
                unsigned sample_count, sample_size;
  
                if (p[0] != 's' || p[1] != 't' || p[2] != 's' || p[3] != 'z')
                        continue;
                PARA_DEBUG_LOG("found stsz@%d\n", i);
                i += 8;
 -              sample_size = aac_read_int32(buf + i);
 +              sample_size = read_u32_be(buf + i);
-               PARA_DEBUG_LOG("sample size: %d\n", sample_size);
+               PARA_DEBUG_LOG("sample size: %u\n", sample_size);
                i += 4;
 -              sample_count = aac_read_int32(buf + i);
 +              sample_count = read_u32_be(buf + i);
                i += 4;
-               PARA_DEBUG_LOG("sample count: %d\n", sample_count);
+               PARA_DEBUG_LOG("sample count: %u\n", sample_count);
                *skip = i;
                return sample_count;
        }
        return -E_STSZ;
  }
  
 -static int atom_cmp(const unsigned char *buf1, const char *buf2)
 +static int atom_cmp(const char *buf1, const char *buf2)
  {
        return memcmp(buf1, buf2, 4)? 1 : 0;
  }
  
 -static int read_atom_header(unsigned char *buf, uint64_t *subsize, unsigned char type[5])
 +static int read_atom_header(char *buf, uint64_t *subsize, char type[5])
  {
 -      int i;
 -      uint64_t size = aac_read_int32(buf);
 +      uint64_t size = read_u32_be(buf);
  
        memcpy(type, buf + 4, 4);
        type[4] = '\0';
        }
        buf += 4;
        size = 0;
 -      for (i = 0; i < 8; i++)
 -              size |= ((uint64_t)buf[i]) << ((7 - i) * 8);
 +      size = read_u64_be(buf);
        *subsize = size;
        return 16;
  }
  
 -static char *get_tag(unsigned char *p, int size)
 +static char *get_tag(char *p, int size)
  {
        char *buf;
  
        return buf;
  }
  
 -static void read_tags(unsigned char *buf, size_t buflen, struct afh_info *afhi)
 +static void read_tags(char *buf, size_t buflen, struct afh_info *afhi)
  {
 -      unsigned char *p = buf;
 +      char *p = buf;
  
        while (p + 32 < buf + buflen) {
 -              unsigned char *q, type1[5], type2[5];
 +              char *q, type1[5], type2[5];
                uint64_t size1, size2;
                int ret, ret2;
  
        }
  }
  
 -static void read_meta(unsigned char *buf, size_t buflen, struct afh_info *afhi)
 +static void read_meta(char *buf, size_t buflen, struct afh_info *afhi)
  {
 -      unsigned char *p = buf;
 +      char *p = buf;
  
        while (p + 4 < buf + buflen) {
  
        }
  }
  
 -static void aac_get_taginfo(unsigned char *buf, size_t buflen,
 -              struct afh_info *afhi)
 +static void aac_get_taginfo(char *buf, size_t buflen, struct afh_info *afhi)
  {
        int i;
        uint64_t subsize;
 -      unsigned char type[5];
 +      char type[5];
  
        for (i = 0; i + 24 < buflen; i++) {
 -              unsigned char *p = buf + i;
 +              char *p = buf + i;
                if (p[0] != 'm' || p[1] != 'e' || p[2] != 't' || p[3] != 'a')
                        continue;
                PARA_INFO_LOG("found metadata at offset %d\n", i);
  }
  
  static ssize_t aac_compute_chunk_table(struct afh_info *afhi,
 -              unsigned char *map, size_t numbytes)
 +              char *map, size_t numbytes)
  {
        int ret, i;
        size_t sum = 0;
        for (i = 1; i <= afhi->chunks_total; i++) {
                if (skip + 4 > numbytes)
                        break;
 -              sum += aac_read_int32(map + skip);
 +              sum += read_u32_be(map + skip);
                afhi->chunk_table[i] = sum;
                skip += 4;
  //            if (i < 10 || i + 10 > afhi->chunks_total)
@@@ -210,33 -212,32 +210,33 @@@ static int aac_get_file_info(char *map
        unsigned char channels = 0;
        mp4AudioSpecificConfig mp4ASC;
        NeAACDecHandle handle = NULL;
 -      unsigned char *umap = (unsigned char *) map;
  
 -      ret = aac_find_esds(umap, numbytes, &skip, &decoder_len);
 +      ret = aac_find_esds(map, numbytes, &skip, &decoder_len);
        if (ret < 0)
                goto out;
 -      aac_get_taginfo(umap, numbytes, afhi);
 +      aac_get_taginfo(map, numbytes, afhi);
        handle = aac_open();
        ret = -E_AAC_AFH_INIT;
 -      if (NeAACDecInit(handle, umap + skip, decoder_len, &rate, &channels))
 +      if (NeAACDecInit(handle, (unsigned char *)map + skip, decoder_len,
 +                      &rate, &channels))
                goto out;
        if (!channels)
                goto out;
        PARA_DEBUG_LOG("rate: %lu, channels: %d\n", rate, channels);
        ret = -E_MP4ASC;
 -      if (NeAACDecAudioSpecificConfig(umap + skip, numbytes - skip, &mp4ASC))
 +      if (NeAACDecAudioSpecificConfig((unsigned char *)map + skip,
 +                      numbytes - skip, &mp4ASC))
                goto out;
        if (!mp4ASC.samplingFrequency)
                goto out;
 -      ret = aac_compute_chunk_table(afhi, umap, numbytes);
 +      ret = aac_compute_chunk_table(afhi, map, numbytes);
        if (ret < 0)
                goto out;
        skip = ret;
        ret = aac_set_chunk_tv(afhi, &mp4ASC, &afhi->seconds_total);
        if (ret < 0)
                goto out;
 -      ret = aac_find_entry_point(umap + skip, numbytes - skip, &skip);
 +      ret = aac_find_entry_point(map + skip, numbytes - skip, &skip);
        if (ret < 0)
                goto out;
        afhi->chunk_table[0] = ret;
diff --combined aac_common.c
index 70a9d77d51b320ee8511f394186528164362273a,fe9b7295f55cc7614278669c670f3bec39827347..812c742cf668e7ad67e6f5b502fbe6c93829f0a3
@@@ -13,7 -13,6 +13,7 @@@
  #include "para.h"
  #include "aac.h"
  #include "error.h"
 +#include "portable_io.h"
  
  /**
   * Get a new libfaad decoder handle.
@@@ -32,7 -31,7 +32,7 @@@ NeAACDecHandle aac_open(void
        return h;
  }
  
 -static unsigned long aac_read_decoder_length(unsigned char *buf, int *description_len)
 +static unsigned long aac_read_decoder_length(char *buf, int *description_len)
  {
        uint8_t b;
        uint8_t numBytes = 0;
   *
   * \return positive on success, negative on errors
   */
 -int aac_find_esds(unsigned char *buf, size_t buflen, size_t *skip,
 +int aac_find_esds(char *buf, size_t buflen, size_t *skip,
                unsigned long *decoder_length)
  {
        size_t i;
  
        for (i = 0; i + 4 < buflen; i++) {
 -              unsigned char *p = buf + i;
 +              char *p = buf + i;
                int description_len;
  
                if (p[0] != 'e' || p[1] != 's' || p[2] != 'd' || p[3] != 's')
                        continue;
                i += 8;
                p = buf + i;
--              PARA_INFO_LOG("found esds@%zu, next: %x\n", i, *p);
++              PARA_INFO_LOG("found esds@%zu, next: %x\n", i, (unsigned)*p);
                if (*p == 3)
                        i += 8;
                else
                        i += 6;
                p = buf + i;
--              PARA_INFO_LOG("next: %x\n", *p);
++              PARA_INFO_LOG("next: %x\n", (unsigned)*p);
                if (*p != 4)
                        continue;
                i += 18;
                p = buf + i;
--              PARA_INFO_LOG("next: %x\n", *p);
++              PARA_INFO_LOG("next: %x\n", (unsigned)*p);
                if (*p != 5)
                        continue;
                i++;
   * \return the position of the first entry in the table on success,
   * -E_STCO on errors.
   */
 -ssize_t aac_find_entry_point(unsigned char *buf, size_t buflen, size_t *skip)
 +ssize_t aac_find_entry_point(char *buf, size_t buflen, size_t *skip)
  {
        ssize_t ret;
        size_t i;
  
        for (i = 0; i + 20 < buflen; i++) {
 -              unsigned char *p = buf + i;
 +              char *p = buf + i;
  
                if (p[0] != 's' || p[1] != 't' || p[2] != 'c' || p[3] != 'o')
                        continue;
                PARA_INFO_LOG("found stco@%zu\n", i);
                i += 12;
 -              ret = aac_read_int32(buf + i); /* first offset */
 +              ret = read_u32_be(buf + i); /* first offset */
                i += 4;
                PARA_INFO_LOG("entry point: %zd\n", ret);
                *skip = i;
diff --combined aacdec_filter.c
index 9791175ecd72d6dcd22ee719f90d1e59481668b3,b40022fe160e21d254eff7ab7672826258b68a0b..5725ce043089361092ddb68e05bb3c60fcf66801
@@@ -86,7 -86,7 +86,7 @@@ static int aacdec_post_select(__a_unuse
        struct btr_node *btrn = fn->btrn;
        struct private_aacdec_data *padd = fn->private_data;
        int i, ret;
 -      unsigned char *p, *inbuf, *outbuffer;
 +      char *p, *inbuf, *outbuffer;
        char *btr_buf;
        size_t len, skip, consumed, loaded;
  
@@@ -97,7 -97,7 +97,7 @@@ next_buffer
        if (ret == 0)
                return 0;
        btr_merge(btrn, fn->min_iqs);
 -      len = btr_next_buffer(btrn, (char **)&inbuf);
 +      len = btr_next_buffer(btrn, &inbuf);
        len = PARA_MIN(len, (size_t)8192);
        consumed = 0;
        if (!padd->initialized) {
                ret = aac_find_esds(inbuf, len, &skip, &padd->decoder_length);
                if (ret < 0) {
                        PARA_INFO_LOG("%s\n", para_strerror(-ret));
 -                      ret = NeAACDecInit(padd->handle, inbuf,
 +                      ret = NeAACDecInit(padd->handle, (unsigned char *)inbuf,
                                len, &rate, &channels);
                        PARA_INFO_LOG("decoder init: %d\n", ret);
                        if (ret < 0) {
                        consumed += skip;
                        p = inbuf + consumed;
                        ret = -E_AACDEC_INIT;
 -                      if (NeAACDecInit2(padd->handle, p,
 +                      if (NeAACDecInit2(padd->handle, (unsigned char *)p,
                                        padd->decoder_length, &rate,
                                        &channels) != 0)
                                goto out;
                }
                padd->sample_rate = rate;
                padd->channels = channels;
-               PARA_INFO_LOG("rate: %u, channels: %d\n",
+               PARA_INFO_LOG("rate: %u, channels: %u\n",
                        padd->sample_rate, padd->channels);
                padd->initialized = 1;
        }
        p = inbuf + consumed;
        //PARA_CRIT_LOG("consumed: %zu (%zu + %zu), have: %zu\n", padd->consumed_total + consumed,
        //      padd->consumed_total, consumed, len - consumed);
 -      outbuffer = NeAACDecDecode(padd->handle, &padd->frame_info, p,
 -              len - consumed);
 +      outbuffer = NeAACDecDecode(padd->handle, &padd->frame_info,
 +              (unsigned char *)p, len - consumed);
        if (padd->frame_info.error) {
                int err = padd->frame_info.error;
                ret = -E_AAC_DECODE;
                        goto success;
                }
                PARA_ERROR_LOG("%s\n", NeAACDecGetErrorMessage(err));
-               PARA_ERROR_LOG("consumed: %zu + %zd + %lu\n",
+               PARA_ERROR_LOG("consumed: %zu + %zu + %lu\n",
                        padd->consumed_total, consumed,
                        padd->frame_info.bytesconsumed);
                if (consumed < len)
diff --combined afs.c
index 071f657ce69c79812d29a982f69cc5c0bbf8f8b7,5f933c5b31e440438acce2e9179121db66c0600e..0946b6df3b0766f82f95f0cd100f039753543350
--- 1/afs.c
--- 2/afs.c
+++ b/afs.c
@@@ -706,7 -706,7 +706,7 @@@ static int open_afs_tables(void
        int i, ret;
  
        get_database_dir();
-       PARA_NOTICE_LOG("opening %u osl tables in %s\n", NUM_AFS_TABLES,
+       PARA_NOTICE_LOG("opening %d osl tables in %s\n", NUM_AFS_TABLES,
                database_dir);
        for (i = 0; i < NUM_AFS_TABLES; i++) {
                ret = afs_tables[i].open(database_dir);
@@@ -1024,13 -1024,6 +1024,13 @@@ __noreturn void afs_init(uint32_t cooki
        register_command_task(cookie, &s);
        s.default_timeout.tv_sec = 0;
        s.default_timeout.tv_usec = 999 * 1000;
 +      ret = write(socket_fd, "\0", 1);
 +      if (ret != 1) {
 +              if (ret == 0)
 +                      errno = EINVAL;
 +              ret = -ERRNO_TO_PARA_ERROR(errno);
 +              goto out_close;
 +      }
        ret = schedule(&s);
        sched_shutdown(&s);
  out_close:
@@@ -1202,7 -1195,7 +1202,7 @@@ __must_check int afs_event(enum afs_eve
                        continue;
                ret = t->event_handler(event, pb, data);
                if (ret < 0) {
-                       PARA_CRIT_LOG("table %s, event %d: %s\n", t->name,
+                       PARA_CRIT_LOG("table %s, event %u: %s\n", t->name,
                                event, para_strerror(-ret));
                        return ret;
                }
diff --combined aft.c
index df295246db0cf1d1d6e3d0b202d43c86332db0f6,e8a18fd13cdca7e957dffa34c59b6e7c736fbd22..77891342313e17295d5b60ea836fd9b187705ae9
--- 1/aft.c
--- 2/aft.c
+++ b/aft.c
@@@ -738,11 -738,11 +738,11 @@@ static void get_duration_buf(int second
        if (!hours) { /* m:ss or mm:ss */
                max_width = opts->mode == LS_MODE_LONG?
                        opts->widths.duration_width : 4;
-               sprintf(buf, "%*u:%02u", max_width - 3, mins, seconds % 60);
+               sprintf(buf, "%*u:%02d", max_width - 3, mins, seconds % 60);
        } else { /* more than one hour => h:mm:ss, hh:mm:ss, hhh:mm:ss, ... */
                max_width = opts->mode == LS_MODE_LONG?
                        opts->widths.duration_width : 7;
-               sprintf(buf, "%*u:%02u:%02u", max_width - 6, hours, mins,
+               sprintf(buf, "%*u:%02u:%02d", max_width - 6, hours, mins,
                        seconds % 60);
        }
  }
@@@ -876,14 -876,14 +876,14 @@@ static int print_list_item(struct ls_da
                para_printf(b,
                        "%s "   /* attributes */
                        "%*u "  /* amp */
-                       "%*d "  /* image_id  */
-                       "%*d "  /* lyrics_id */
-                       "%*d "  /* bitrate */
+                       "%*u "  /* image_id  */
+                       "%*u "  /* lyrics_id */
+                       "%*u "  /* bitrate */
                        "%*s "  /* audio format */
-                       "%*d "  /* frequency */
-                       "%d "   /* channels */
+                       "%*u "  /* frequency */
+                       "%u "   /* channels */
                        "%s "   /* duration */
-                       "%*d "  /* num_played */
+                       "%*u "  /* num_played */
                        "%s "   /* last_played */
                        "%s\n", /* path */
                        att_buf,
        WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%" PRIu32 "\n",
                afhi->seconds_total);
        WRITE_STATUS_ITEM(b, SI_LAST_PLAYED, "%s\n", last_played_time);
-       WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%d\n", afsi->num_played);
+       WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%u\n", afsi->num_played);
        WRITE_STATUS_ITEM(b, SI_AMPLIFICATION, "%u\n", afsi->amp);
        WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n", tv2ms(&afhi->chunk_tv));
        WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%" PRIu32 "\n",
@@@ -1410,14 -1410,10 +1410,14 @@@ int com_ls(struct command_context *cc
                                return -E_AFT_SYNTAX;
                        }
                }
 -              if (!strcmp(arg, "-p")) {
 +              if (!strcmp(arg, "-p") || !strcmp(arg, "-F")) {
                        flags |= LS_FLAG_FULL_PATH;
                        continue;
                }
 +              if (!strcmp(arg, "-b")) {
 +                      flags &= ~LS_FLAG_FULL_PATH;
 +                      continue;
 +              }
                if (!strcmp(arg, "-a")) {
                        flags |= LS_FLAG_ADMISSIBLE_ONLY;
                        continue;
@@@ -2625,7 -2621,7 +2625,7 @@@ static int aft_open(const char *dir
        if (ret >= 0) {
                unsigned num;
                osl_get_num_rows(audio_file_table, &num);
-               PARA_INFO_LOG("audio file table contains %d files\n", num);
+               PARA_INFO_LOG("audio file table contains %u files\n", num);
                return ret;
        }
        PARA_NOTICE_LOG("failed to open audio file table\n");
diff --combined crypt_common.c
index b39ee5e4cb6fce2b28a3b87034350f321d7cd75d,8e52603fffc12ba701ec5a8456634cd751ea4d41..a05572df85b1de5fb5e1043abfc34c66e26c65e7
@@@ -45,6 -45,166 +45,6 @@@ size_t is_ssh_rsa_key(char *data, size_
        return cp - data;
  }
  
 -/*
 - * This base64/uudecode stuff below is taken from openssh-5.2p1, Copyright (c)
 - * 1996 by Internet Software Consortium.  Portions Copyright (c) 1995 by
 - * International Business Machines, Inc.
 - */
 -
 -static const char Base64[] =
 -      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 -static const char Pad64 = '=';
 -
 -/**
 - * base64-decode a buffer.
 - *
 - * \param src The buffer to decode.
 - * \param target Result is stored here.
 - * \param targsize Number of bytes of \a target.
 - *
 - * Skips all whitespace anywhere. Converts characters, four at a time, starting
 - * at (or after) src from base - 64 numbers into three 8 bit bytes in the
 - * target area.
 - *
 - * \return The number of data bytes stored at the target, -E_BASE64 on errors.
 - */
 -int base64_decode(char const *src, unsigned char *target, size_t targsize)
 -{
 -      unsigned int tarindex, state;
 -      int ch;
 -      char *pos;
 -
 -      state = 0;
 -      tarindex = 0;
 -
 -      while ((ch = *src++) != '\0') {
 -              if (para_isspace(ch)) /* Skip whitespace anywhere. */
 -                      continue;
 -
 -              if (ch == Pad64)
 -                      break;
 -
 -              pos = strchr(Base64, ch);
 -              if (pos == NULL) /* A non-base64 character. */
 -                      return -E_BASE64;
 -
 -              switch (state) {
 -              case 0:
 -                      if (tarindex >= targsize)
 -                              return -E_BASE64;
 -                      target[tarindex] = (pos - Base64) << 2;
 -                      state = 1;
 -                      break;
 -              case 1:
 -                      if (tarindex + 1 >= targsize)
 -                              return -E_BASE64;
 -                      target[tarindex] |= (pos - Base64) >> 4;
 -                      target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
 -                      tarindex++;
 -                      state = 2;
 -                      break;
 -              case 2:
 -                      if (tarindex + 1 >= targsize)
 -                              return -E_BASE64;
 -                      target[tarindex] |= (pos - Base64) >> 2;
 -                      target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
 -                      tarindex++;
 -                      state = 3;
 -                      break;
 -              case 3:
 -                      if (tarindex >= targsize)
 -                              return -E_BASE64;
 -                      target[tarindex] |= pos - Base64;
 -                      tarindex++;
 -                      state = 0;
 -                      break;
 -              }
 -      }
 -
 -      /*
 -       * We are done decoding Base-64 chars.  Let's see if we ended
 -       * on a byte boundary, and/or with erroneous trailing characters.
 -       */
 -
 -      if (ch == Pad64) {              /* We got a pad char. */
 -              ch = *src++;            /* Skip it, get next. */
 -              switch (state) {
 -              case 0:         /* Invalid = in first position */
 -              case 1:         /* Invalid = in second position */
 -                      return -E_BASE64;
 -
 -              case 2:         /* Valid, means one byte of info */
 -                      /* Skip any number of spaces. */
 -                      for (; ch != '\0'; ch = *src++)
 -                              if (!isspace(ch))
 -                                      break;
 -                      /* Make sure there is another trailing = sign. */
 -                      if (ch != Pad64)
 -                              return -E_BASE64;
 -                      ch = *src++;            /* Skip the = */
 -                      /* Fall through to "single trailing =" case. */
 -                      /* FALLTHROUGH */
 -
 -              case 3:         /* Valid, means two bytes of info */
 -                      /*
 -                       * We know this char is an =.  Is there anything but
 -                       * whitespace after it?
 -                       */
 -                      for (; ch != '\0'; ch = *src++)
 -                              if (!isspace(ch))
 -                                      return -E_BASE64;
 -
 -                      /*
 -                       * Now make sure for cases 2 and 3 that the "extra"
 -                       * bits that slopped past the last full byte were
 -                       * zeros.  If we don't check them, they become a
 -                       * subliminal channel.
 -                       */
 -                      if (target[tarindex] != 0)
 -                              return -E_BASE64;
 -              }
 -      } else {
 -              /*
 -               * We ended by seeing the end of the string.  Make sure we
 -               * have no partial bytes lying around.
 -               */
 -              if (state != 0)
 -                      return -E_BASE64;
 -      }
 -
 -      return tarindex;
 -}
 -
 -/**
 - * uudecode a buffer.
 - *
 - * \param src The buffer to decode.
 - * \param target Result buffer.
 - * \param targsize The length of \a target in bytes.
 - *
 - * This is just a simple wrapper for base64_decode() which strips whitespace.
 - *
 - * \return The return value of the underlying call to base64_decode().
 - */
 -int uudecode(const char *src, unsigned char *target, size_t targsize)
 -{
 -      int len;
 -      char *encoded, *p;
 -
 -      /* copy the 'readonly' source */
 -      encoded = para_strdup(src);
 -      /* skip whitespace and data */
 -      for (p = encoded; *p == ' ' || *p == '\t'; p++)
 -              ;
 -      for (; *p != '\0' && *p != ' ' && *p != '\t'; p++)
 -              ;
 -      /* and remove trailing whitespace because base64_decode needs this */
 -      *p = '\0';
 -      len = base64_decode(encoded, target, targsize);
 -      free(encoded);
 -      return len;
 -}
 -
  /**
   * Read a 4-byte number from a buffer in big-endian format.
   *
@@@ -96,7 -256,7 +96,7 @@@ int check_ssh_key_header(const unsigne
                return -E_SSH_KEY_HEADER;
        if (rlen < strlen(KEY_TYPE_TXT))
                return -E_SSH_KEY_HEADER;
-       PARA_DEBUG_LOG("type: %s, rlen: %d\n", p, rlen);
+       PARA_DEBUG_LOG("type: %s, rlen: %u\n", p, rlen);
        if (strncmp((char *)p, KEY_TYPE_TXT, strlen(KEY_TYPE_TXT)))
                return -E_SSH_KEY_HEADER;
        return 4 + rlen;
diff --combined fade.c
index 95bb1d59ffd60f277f4569e44c8909c3fe060c76,2a4eb1e1829168f0b94ebc24bc8138be5e9f226c..2a001ebacde964eb1f710413540cc23f2bc85699
--- 1/fade.c
--- 2/fade.c
+++ b/fade.c
@@@ -67,7 -67,7 +67,7 @@@ static int fade(struct mixer *m, struc
        if (ret < 0)
                goto out;
        vol = ret;
-       PARA_NOTICE_LOG("fading %s from %d to %d in %d seconds\n",
+       PARA_NOTICE_LOG("fading %s from %d to %d in %u seconds\n",
                conf.mixer_channel_arg, vol, new_vol, secs);
        diff = new_vol - vol;
        if (!diff) {
@@@ -203,7 -203,7 +203,7 @@@ static int sweet_dreams(struct mixer *m
                tm = localtime(&t1);
        }
        wake_time_epoch = mktime(tm);
-       PARA_INFO_LOG("waketime: %u:%02u\n", tm->tm_hour, tm->tm_min);
+       PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min);
        client_cmd("stop");
        sleep(1);
        if (fot) {
@@@ -333,17 -333,6 +333,17 @@@ __noreturn static void print_help_and_d
        exit(0);
  }
  
 +/**
 + * The main function of para_fade.
 + *
 + * The executable is linked with the alsa or the oss mixer API, or both. It has
 + * a custom log function which prefixes log messages with the current date.
 + *
 + * \param argc Argument counter.
 + * \param argv Argument vector.
 + *
 + * \return EXIT_SUCCESS or EXIT_FAILURE.
 + */
  int main(int argc, char *argv[])
  {
        int ret;
diff --combined gcrypt.c
index 289748e84d16dbca133b9280dc2027e5d9c2ec67,32dd227f619aadfa3f00f2e75980409821b58698..7c19aeb0c3edc022c5b0f0425a202e37fd38d906
+++ b/gcrypt.c
@@@ -15,7 -15,6 +15,7 @@@
  #include "crypt.h"
  #include "crypt_backend.h"
  #include "fd.h"
 +#include "base64.h"
  
  //#define GCRYPT_DEBUG 1
  
@@@ -240,11 -239,12 +240,11 @@@ static int decode_key(const char *key_f
                key[j++] = begin[i];
        }
        key[j] = '\0';
 -      blob_size = key_size * 2;
 -      blob = para_malloc(blob_size);
 -      ret = base64_decode(key, blob, blob_size);
 +      ret = base64_decode(key, j, (char **)&blob, &blob_size);
        free(key);
        if (ret < 0)
                goto free_unmap;
 +      ret = blob_size;
        goto unmap;
  free_unmap:
        free(blob);
@@@ -388,7 -388,7 +388,7 @@@ static int read_bignum(unsigned char *s
                for (i = 0; i < num_bytes; i++, cp++)
                        bn_size = (bn_size << 8) + *cp;
        }
-       PARA_DEBUG_LOG("bn_size %d (0x%x)\n", bn_size, bn_size);
+       PARA_DEBUG_LOG("bn_size %d (0x%x)\n", bn_size, (unsigned)bn_size);
        gret = gcry_mpi_scan(bn, GCRYMPI_FMT_STD, cp, bn_size, NULL);
        if (gret) {
                PARA_ERROR_LOG("%s while scanning n\n",
@@@ -586,7 -586,7 +586,7 @@@ static int get_asn_public_key(const cha
        key->num_bytes = n_size;
        *result = key;
        ret = n_size;
-       PARA_INFO_LOG("successfully read %u bit asn public key\n", n_size * 8);
+       PARA_INFO_LOG("successfully read %d bit asn public key\n", n_size * 8);
  
  release_e:
        gcry_mpi_release(e);
@@@ -606,9 -606,13 +606,9 @@@ static int get_ssh_public_key(unsigned 
        gcry_mpi_t e = NULL, n = NULL;
  
        PARA_DEBUG_LOG("decoding %d byte public rsa-ssh key\n", size);
 -      if (size > INT_MAX / 4)
 -              return -ERRNO_TO_PARA_ERROR(EOVERFLOW);
 -      blob = para_malloc(2 * size);
 -      ret = uudecode((char *)data, blob, 2 * size);
 +      ret = uudecode((char *)data, size, (char **)&blob, &decoded_size);
        if (ret < 0)
                goto free_blob;
 -      decoded_size = ret;
        end = blob + decoded_size;
        dump_buffer("decoded key", blob, decoded_size);
        ret = check_ssh_key_header(blob, decoded_size);
                goto release_n;
        }
        ret = nr_scanned / 32 * 32;
-       PARA_INFO_LOG("successfully read %u bit ssh public key\n", ret * 8);
+       PARA_INFO_LOG("successfully read %d bit ssh public key\n", ret * 8);
  release_n:
        gcry_mpi_release(n);
  release_e:
diff --combined play.c
index 108db598a51ebb28f72cb03a10c31ebfcb44ca6e,c35757a9ae4aec542da3ce94267305aff705b37d..46e8ff7d6f099e016cca6338dc399e210b9e5c97
--- 1/play.c
--- 2/play.c
+++ b/play.c
@@@ -328,7 -328,8 +328,7 @@@ static int open_new_file(struct play_ta
        pt->rn.receiver = afh_recv;
        ret = afh_recv->open(&pt->rn);
        if (ret < 0) {
 -              PARA_ERROR_LOG("could not open %s: %s\n", path,
 -                      para_strerror(-ret));
 +              PARA_ERROR_LOG("could not open %s\n", path);
                goto fail;
        }
        pt->audio_format_num = ret;
@@@ -387,7 -388,6 +387,7 @@@ static int load_file(struct play_task *
        /* set up decoding filter */
        af = audio_format_name(pt->audio_format_num);
        tmp = make_message("%sdec", af);
 +      PARA_INFO_LOG("decoder: %s\n", tmp);
        ret = check_filter_arg(tmp, &pt->fn.conf);
        freep(&tmp);
        if (ret < 0)
                        .handler = decoder->execute, .context = &pt->fn));
        if (decoder->open)
                decoder->open(&pt->fn);
 +      PARA_INFO_LOG("buffer tree:\n");
 +      btr_log_tree(pt->rn.btrn, LL_INFO);
  
        /* setup default writer */
        pt->wn.conf = check_writer_arg_or_die(NULL, &pt->wn.writer_num);
@@@ -455,8 -453,6 +455,8 @@@ again
                pt->next_file = pt->current_file;
        ret = load_file(pt);
        if (ret < 0) {
 +              PARA_ERROR_LOG("%s: marking file as invalid\n",
 +                      para_strerror(-ret));
                pt->invalid[pt->next_file] = true;
                pt->rq = CRT_NONE;
                goto again;
@@@ -788,7 -784,7 +788,7 @@@ static void list_file(struct play_task 
        char *buf;
        size_t sz;
  
-       sz = xasprintf(&buf, "%s %4u %s\n", num == pt->current_file?
+       sz = xasprintf(&buf, "%s %4d %s\n", num == pt->current_file?
                "*" : " ", num, conf.inputs[num]);
        btr_add_output(buf, sz, pt->btrn);
  }
diff --combined server.c
index ca71c4d8860e49224ffd0f2203ed76a7253a1a01,c90045c30d81ece771a679f648b203c3aa000910..1f93194474374e7450fec6a4895309c4529c5226
+++ b/server.c
@@@ -411,9 -411,8 +411,9 @@@ static int init_afs(int argc, char **ar
  {
        int ret, afs_server_socket[2];
        pid_t afs_pid;
 +      char c;
  
 -      ret = socketpair(PF_UNIX, SOCK_DGRAM, 0, afs_server_socket);
 +      ret = socketpair(PF_UNIX, SOCK_STREAM, 0, afs_server_socket);
        if (ret < 0)
                exit(EXIT_FAILURE);
        get_random_bytes_or_die((unsigned char *)&afs_socket_cookie,
                exit(EXIT_FAILURE);
        if (afs_pid == 0) { /* child (afs) */
                int i;
 +
                for (i = argc - 1; i >= 0; i--)
                        memset(argv[i], 0, strlen(argv[i]));
                sprintf(argv[0], "para_server (afs)");
        }
        mmd->afs_pid = afs_pid;
        close(afs_server_socket[1]);
 +      if (read(afs_server_socket[0], &c, 1) <= 0) {
 +              PARA_EMERG_LOG("early afs exit\n");
 +              exit(EXIT_FAILURE);
 +      }
        ret = mark_fd_nonblocking(afs_server_socket[0]);
        if (ret < 0)
                exit(EXIT_FAILURE);
@@@ -463,7 -457,7 +463,7 @@@ static void server_init(int argc, char 
                .check_ambiguity = 0,
                .print_errors = 1
        };
 -      int afs_socket;
 +      int afs_socket, daemon_pipe = -1;
  
        valid_fd_012();
        init_random_seed_or_die();
        init_user_list(user_list_file);
        /* become daemon */
        if (conf.daemon_given)
 -              daemonize(true /* parent waits for SIGTERM */);
 +              daemon_pipe = daemonize(true /* parent waits for us */);
        PARA_NOTICE_LOG("initializing audio format handlers\n");
        afh_init();
  
        PARA_NOTICE_LOG("initializing virtual streaming system\n");
        init_vss_task(afs_socket, &sched);
        init_server_command_task(argc, argv);
 -      if (conf.daemon_given)
 -              kill(getppid(), SIGTERM);
 +      if (daemon_pipe >= 0) {
 +              if (write(daemon_pipe, "\0", 1) < 0) {
 +                      PARA_EMERG_LOG("daemon_pipe: %s", strerror(errno));
 +                      exit(EXIT_FAILURE);
 +              }
 +              close(daemon_pipe);
 +      }
        PARA_NOTICE_LOG("server init complete\n");
  }
  
@@@ -537,7 -526,7 +537,7 @@@ out
        prev_uptime = uptime;
        prev_events = mmd->events;
        mmd->vss_status_flags = mmd->new_vss_status_flags;
-       PARA_DEBUG_LOG("%d events, forcing status update\n", mmd->events);
+       PARA_DEBUG_LOG("%u events, forcing status update\n", mmd->events);
        killpg(0, SIGUSR1);
  }
  
diff --combined wma_common.c
index 27cb51d0434367e168fa49554e05bf1f13d9f473,95bb9ace57665ba0b9050f9fa512a750a913d52a..6d57c00be2d2627624f5642a74948723bc2726fb
@@@ -42,17 -42,6 +42,17 @@@ const char *search_pattern(const char *
        return NULL;
  }
  
-       PARA_DEBUG_LOG("found file property guid@%0x\n", (int)(p - buf));
 +static int find_file_properties(const char *buf, int len)
 +{
 +      const char pattern[] = {0xa1, 0xdc, 0xab, 0x8c};
 +      const char *p = search_pattern(pattern, sizeof(pattern), buf, len);
 +
 +      if (!p)
 +              return -E_WMA_NO_GUID;
++      PARA_DEBUG_LOG("found file property guid@%0x\n", (unsigned)(p - buf));
 +      return p - buf + 16;
 +}
 +
  /*
     40 9e 69 f8 4d 5b cf 11  a8 fd 00 80 5f 5c 44 2b
   */
@@@ -63,7 -52,7 +63,7 @@@ static int find_audio_stream_info(cons
  
        if (!p)
                return -E_WMA_NO_GUID;
-       PARA_DEBUG_LOG("found audio stream guid@%0x\n", (int)(p - buf));
+       PARA_DEBUG_LOG("found audio stream guid@%0x\n", (unsigned)(p - buf));
        return p - buf + 16;
  }
  
@@@ -111,33 -100,18 +111,33 @@@ int read_asf_header(const char *buf, in
                ahi->sample_rate);
  
        ahi->bit_rate = 8 * read_u16(start + 46);
-       PARA_INFO_LOG("bit rate: %d\n", ahi->bit_rate);
+       PARA_INFO_LOG("bit rate: %u\n", ahi->bit_rate);
  
        ahi->block_align = read_u16(start + 50);
        PARA_INFO_LOG("block_align: %d\n", ahi->block_align);
  
        ahi->flags1 = read_u32(start + 56);
        ahi->flags2 = read_u16(start + 60);
-       PARA_INFO_LOG("read_asf_header: flags1: %d, flags2: %d\n",
 -      PARA_INFO_LOG("read_asf_header: flags1: %u, flag2: %u\n",
++      PARA_INFO_LOG("read_asf_header: flags1: %u, flags2: %u\n",
                ahi->flags1, ahi->flags2);
        ahi->use_exp_vlc = ahi->flags2 & 0x0001;
        ahi->use_bit_reservoir = ahi->flags2 & 0x0002;
        ahi->use_variable_block_len = ahi->flags2 & 0x0004;
 +
 +      ret = find_file_properties(buf, ahi->header_len);
 +      if (ret < 0)
 +              return ret;
 +      /* file property header is always 88 bytes (sans GUID) */
 +      if (ret + 88 > loaded)
 +              return 0;
 +      start = buf + ret;
 +      ahi->packet_size = read_u32(start + 76); /* min packet size */
 +      /* we only support fixed packet sizes */
 +      if (ahi->packet_size != read_u32(start + 80)) /* min != max */
 +              return -E_BAD_ASF_FILE_PROPS;
 +      if (ahi->packet_size <= ahi->block_align)
 +              return -E_BAD_ASF_FILE_PROPS;
 +      PARA_INFO_LOG("packet size: %u\n", ahi->packet_size);
        return 1;
  }
  
diff --combined wmadec_filter.c
index 31a13c5094a239fca2ebd519553821933b838ba7,7691553e4723ebaac01294ca40290be9b3eb2899..4c7c047a482e2b3f256cfb8c12dcd6b4de3a7500
@@@ -371,8 -371,8 +371,8 @@@ static int wma_init(struct private_wmad
                else
                        high_freq = high_freq * 0.5;
        }
-       PARA_INFO_LOG("channels=%d sample_rate=%d "
-               "bitrate=%d block_align=%d\n",
+       PARA_INFO_LOG("channels=%u sample_rate=%u "
+               "bitrate=%u block_align=%d\n",
                ahi->channels, ahi->sample_rate,
                ahi->bit_rate, ahi->block_align);
        PARA_INFO_LOG("frame_len=%d, bps=%f bps1=%f "
@@@ -1028,7 -1028,7 +1028,7 @@@ static inline int16_t av_clip_int16(in
  /* Decode a frame of frame_len samples. */
  static int wma_decode_frame(struct private_wmadec_data *pwd, int16_t *samples)
  {
 -      int ret, i, n, ch, incr;
 +      int ret, i, ch;
        int16_t *ptr;
        float *iptr;
  
        }
  
        /* convert frame to integer */
 -      n = pwd->frame_len;
 -      incr = pwd->ahi.channels;
        for (ch = 0; ch < pwd->ahi.channels; ch++) {
                ptr = samples + ch;
                iptr = pwd->frame_out[ch];
  
 -              for (i = 0; i < n; i++) {
 +              for (i = 0; i < pwd->frame_len; i++) {
                        *ptr = av_clip_int16(lrintf(*iptr++));
 -                      ptr += incr;
 +                      ptr += pwd->ahi.channels;
                }
                /* prepare for next block */
                memmove(&pwd->frame_out[ch][0], &pwd->frame_out[ch][pwd->frame_len],
@@@ -1066,13 -1068,10 +1066,13 @@@ static int wma_decode_superframe(struc
  
        if (buf_size == 0) {
                pwd->last_superframe_len = 0;
 +              *data_size = 0;
                return 0;
        }
 -      if (buf_size < pwd->ahi.block_align)
 +      if (buf_size < pwd->ahi.block_align) {
 +              *data_size = 0;
                return 0;
 +      }
        buf_size = pwd->ahi.block_align;
        samples = data;
        init_get_bits(&pwd->gb, buf, buf_size);
@@@ -1210,7 -1209,7 +1210,7 @@@ next_buffer
        if (ret == 0)
                return 0;
        btr_merge(btrn, fn->min_iqs);
 -      len = btr_next_buffer(btrn, (char **)&in);
 +      len = btr_next_buffer(btrn, &in);
        ret = -E_WMADEC_EOF;
        if (len < fn->min_iqs)
                goto err;
                        fn->min_iqs += 4096;
                        goto next_buffer;
                }
 -              fn->min_iqs = 2 * (WMA_FRAME_SKIP + pwd->ahi.block_align);
 +              fn->min_iqs = 2 * pwd->ahi.packet_size;
                fn->private_data = pwd;
                converted = pwd->ahi.header_len;
                goto success;
        }
 -      fn->min_iqs = WMA_FRAME_SKIP + pwd->ahi.block_align;
 +      fn->min_iqs = pwd->ahi.packet_size;
        if (fn->min_iqs > len)
                goto success;
        out_size = WMA_OUTPUT_BUFFER_SIZE;
                free(out);
                goto err;
        }
 -      out = para_realloc(out, out_size);
 -      if (out_size > 0)
 +      if (out_size > 0) {
 +              out = para_realloc(out, out_size);
                btr_add_output(out, out_size, btrn);
 -      converted += ret + WMA_FRAME_SKIP;
 +      } else
 +              free(out);
 +      converted += pwd->ahi.packet_size;
  success:
        btr_consume(btrn, converted);
        return 0;