]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fecdec_filter.c
Avoid division by zero in setup_next_fec_group().
[paraslash.git] / fecdec_filter.c
index 6ca0b037da0f55be826137facc4632415648329c..d5593f25d02c5cde248e0c775a1d3235a279ef8f 100644 (file)
@@ -198,6 +198,8 @@ static int add_slice(char *buf, struct fecdec_group *fg)
        int r, slice_num;
 
        if (group_complete(fg)) {
+               PARA_DEBUG_LOG("group complete, ignoring slice %d\n",
+                       fg->h.slice_num);
                fg->num_received_slices++;
                return 0;
        }
@@ -265,7 +267,7 @@ static int read_fec_header(char *buf, size_t len, struct fec_header *h)
 
        h->slice_num = read_u8(buf + 18);
        h->slice_bytes = read_u16(buf + 20);
-       if (!h->group_bytes && & h->slice_bytes)
+       if (!memcmp(buf, FEC_EOF_PACKET, FEC_EOF_PACKET_LEN))
                return -E_FECDEC_EOF;
 //     PARA_DEBUG_LOG("group %u, slize %u, slices per group: %u\n",
 //             h->group_num, h->slice_num, h->slices_per_group);
@@ -285,14 +287,8 @@ static int dispatch_slice(char *buf, size_t len, struct fec_header *h,
        ret = get_group(h, pfd, &fg);
        if (ret < 0)
                return ret;
-       if (group_complete(fg)) {
-               PARA_DEBUG_LOG("group complete, ignoring slice %d\n",
-                       h->slice_num);
+       if (!add_slice(buf, fg))
                return 1;
-       }
-       ret = add_slice(buf, fg);
-       if (ret < 0)
-               return ret;
        if (group_complete(fg)) {
                if (!pfd->fec) {
                        int k = h->data_slices_per_group, n = h->slices_per_group;
@@ -308,7 +304,7 @@ static int dispatch_slice(char *buf, size_t len, struct fec_header *h,
        return 1;
 }
 
-static int fecdec(char *buf, size_t len, struct filter_node *fn)
+static ssize_t fecdec(char *buf, size_t len, struct filter_node *fn)
 {
        int ret;
        struct fec_header h;