Skip to content

Commit

Permalink
ffs 2024-11-04 (826663cc) (#4391)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://github.com/GTkorvo/ffs.git

at commit 826663cc6a14acdc4692bb25a07df3b3686b3645 (master).
  • Loading branch information
eisenhauer authored Nov 5, 2024
1 parent c3cc3a2 commit 7a45dc4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions thirdparty/ffs/ffs/ffs/ffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ ensure_writev_room(estate s, int add_count)
}


void
roundup_tmp_buffer(FFSBuffer buf, int req_alignment)
{
int pad = (req_alignment - buf->tmp_buffer_size) & (req_alignment -1); /* only works if req_align is power of two */
switch (req_alignment) {
case 1: case 2: case 4: case 8: case 16: break;
default:
assert(0);
}
if (pad) {
buf->tmp_buffer = realloc(buf->tmp_buffer, buf->tmp_buffer_size + pad);
memset((char*)buf->tmp_buffer + buf->tmp_buffer_size, 0, pad);
buf->tmp_buffer_size += pad;
}
}

size_t
allocate_tmp_space(estate s, FFSBuffer buf, size_t length, int req_alignment, size_t *tmp_data_loc)
{
Expand Down Expand Up @@ -277,6 +293,8 @@ FFSencode_internal(FFSBuffer b, FMFormat fmformat, void *data, size_t *buf_size,
tmp_data += fmformat->server_ID.length;
memcpy(tmp_data, &record_len, 8);
}
// round up malloc to 8
roundup_tmp_buffer(b, 8);
free_addr_list(&state);
*buf_size = state.output_len;
if (!state.iovec_is_stack) {
Expand Down

0 comments on commit 7a45dc4

Please sign in to comment.