Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFS Upstream #4391

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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