URI:
       tRemove some more malloc() - libeech - bittorrent library
  HTML git clone git://z3bra.org/libeech.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit fe9bdcbb5f33ca30a4e78fd4bbd4942f846049b9
   DIR parent e399823985f0dc7169562860c68296139e259d87
  HTML Author: z3bra <contactatz3bradotorg>
       Date:   Fri, 29 Jun 2018 23:06:12 +0200
       
       Remove some more malloc()
       
       Diffstat:
         M libeech.c                           |       9 +++------
         M libeech.h                           |       8 ++++----
       
       2 files changed, 7 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/libeech.c b/libeech.c
       t@@ -228,7 +228,8 @@ static long
        readpiece(struct torrent *t, struct piece *p, long n)
        {
                int i;
       -        size_t off, fp, sz;
       +        size_t off, fp;
       +        ssize_t sz;
                FILE *fh = NULL;
        
                /* last piece might be truncated, so recalculate it*/
       t@@ -592,17 +593,13 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s)
                /* pieces related values */
                t->psz = bekint(&t->info, "piece length", 12);
                t->npiece = t->sz / t->psz + !!(t->sz % t->psz);
       -        t->ph = malloc(t->npiece * 20);
                bekstr(&t->info, "pieces", 6, &v);
                memcpy(t->ph, v.off, v.end - v.off);
       -        t->bf = malloc(t->npiece / 8 + 1);
                memset(t->bf, 0, t->npiece / 8 + 1);
        
                for (i = 0; i < t->npiece; i++) {
       -                if (readpiece(t, &piece, i) > 0 && !chkpiece(t, &piece, i)) {
       -                        printf("PIECE %ld/%ld\n", i + 1, t->npiece);
       +                if (readpiece(t, &piece, i) > 0 && !chkpiece(t, &piece, i))
                                setbit(t->bf, i);
       -                }
                }
        
                return 1;
   DIR diff --git a/libeech.h b/libeech.h
       t@@ -22,7 +22,7 @@ enum {
        
        struct piece {
                int n;
       -        size_t sz;
       +        ssize_t sz;
                char blks[PCESIZ];
                char bf[PCESIZ / BLKSIZ];
        };
       t@@ -35,7 +35,7 @@ struct peer {
                char rxbuf[MSGSIZ];
                long rxbufsz;
                char bf[PCENUM / 8];
       -        struct piece *piece;
       +        struct piece piece;
                struct peer *next;
        };
        
       t@@ -48,8 +48,8 @@ struct torrent {
                char id[21];
                char ih[20];
                char tr[PATH_MAX];
       -        char *ph;
       -        char *bf;
       +        char bf[PCENUM];
       +        char ph[PCENUM];
                struct be be;
                struct be info;
                struct peer *peers;