mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-07 21:18:05 +02:00
Ensure ply-buffer data block always terminates with a '\0'
In some instances, ply-buffer did not terminate the data block with a '\0'. Doing so allows the data to be used as a string. Additionally it now tries harder to deal with very long additions to the buffer by repeatedly expanding the capacity and dealing with appends larger than the maximum buffer size.
This commit is contained in:
parent
468f52ae50
commit
66edc73d26
1 changed files with 14 additions and 8 deletions
|
|
@ -83,6 +83,7 @@ ply_buffer_remove_bytes (ply_buffer_t *buffer,
|
|||
buffer->size - bytes_to_remove);
|
||||
buffer->size -= bytes_to_remove;
|
||||
}
|
||||
buffer->data[buffer->size] = '\0';
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -94,6 +95,7 @@ ply_buffer_remove_bytes_at_end (ply_buffer_t *buffer,
|
|||
bytes_to_remove = MIN (buffer->size, bytes_to_remove);
|
||||
|
||||
buffer->size -= bytes_to_remove;
|
||||
buffer->data[buffer->size] = '\0';
|
||||
}
|
||||
|
||||
ply_buffer_t *
|
||||
|
|
@ -176,22 +178,25 @@ ply_buffer_append_with_non_literal_format_string (ply_buffer_t *buffer,
|
|||
|
||||
void
|
||||
ply_buffer_append_bytes (ply_buffer_t *buffer,
|
||||
const void *bytes,
|
||||
const void *bytes_in,
|
||||
size_t length)
|
||||
{
|
||||
assert (buffer != NULL);
|
||||
assert (bytes != NULL);
|
||||
assert (bytes_in != NULL);
|
||||
assert (length != 0);
|
||||
|
||||
if ((buffer->size + length) >= buffer->capacity)
|
||||
|
||||
const uint8_t *bytes = bytes_in;
|
||||
|
||||
if (length >PLY_BUFFER_MAX_BUFFER_CAPACITY){
|
||||
bytes += length - (PLY_BUFFER_MAX_BUFFER_CAPACITY-1);
|
||||
length = (PLY_BUFFER_MAX_BUFFER_CAPACITY-1);
|
||||
}
|
||||
|
||||
while ((buffer->size + length) >= buffer->capacity)
|
||||
{
|
||||
if (!ply_buffer_increase_capacity (buffer))
|
||||
{
|
||||
ply_buffer_remove_bytes (buffer, length);
|
||||
|
||||
if ((buffer->size + length) >= buffer->capacity)
|
||||
if (!ply_buffer_increase_capacity (buffer))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -201,6 +206,7 @@ ply_buffer_append_bytes (ply_buffer_t *buffer,
|
|||
bytes, length);
|
||||
|
||||
buffer->size += length;
|
||||
buffer->data[buffer->size] = '\0';
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue