- buf = vsst->header_buf;
- for (i = 0; i < g->num_header_slices; i++) {
- uint32_t payload_size;
- if (buf + g->slice_bytes <= vsst->header_buf + vsst->header_len) {
- fc->src_data[i] = (const unsigned char *)buf;
- buf += g->slice_bytes;
- continue;
- }
- /*
- * Can not use vss->header_buf for this slice as it
- * goes beyond the buffer. This slice will not be fully
- * used.
- */
- payload_size = vsst->header_buf + vsst->header_len - buf;
- memcpy(fc->extra_header_buf, buf, payload_size);
- if (payload_size < g->slice_bytes)
- memset(fc->extra_header_buf + payload_size, 0,
- g->slice_bytes - payload_size);
- /*
- * There might be more than one header slice to fill although
- * only the first one will be used. Set all header slices to
- * our extra buffer.
- */
- while (i < g->num_header_slices)
- fc->src_data[i++] = fc->extra_header_buf;
- break; /* we don't want i to be increased. */
+ for (i = 0, src_copied = 0; i < g->num_header_slices; i++) {
+ copy = PARA_MIN((size_t)g->slice_bytes, vsst->header_len - src_copied);
+ if (copy == 0)
+ break;
+ memcpy(fc->src_data[i], vsst->header_buf + src_copied, copy);
+ if (copy < g->slice_bytes)
+ memset(fc->src_data[i] + copy, 0, g->slice_bytes - copy);
+ src_copied += copy;