Skip null-terminating a result already null-terminated by strlcpy()

This commit is contained in:
apio 2022-11-30 11:14:11 +01:00
parent e922cfe8b9
commit eeb7bccda8

View File

@ -78,12 +78,9 @@ size_t minitar_align_up_to_block_size(size_t size)
void minitar_parse_metadata_from_tar_header(const struct tar_header* hdr, struct minitar_entry_metadata* metadata) void minitar_parse_metadata_from_tar_header(const struct tar_header* hdr, struct minitar_entry_metadata* metadata)
{ {
if (!strlen(hdr->prefix)) // If prefix is null, the full path is only the "name" field of the tar header. if (!strlen(hdr->prefix)) // If prefix is null, the full path is only the "name" field of the tar header.
{ minitar_strlcpy(
size_t size = minitar_strlcpy(metadata->path, hdr->name, 100); metadata->path, hdr->name,
if (size >= 100) metadata->path[100] = '\0'; 101); // We use 101 instead of 100 so that we copy the full "name" field even if it is not null-terminated.
else
metadata->path[size] = '\0';
}
else // Construct the path by first taking the "prefix" field, then adding a slash, then concatenating the "name" else // Construct the path by first taking the "prefix" field, then adding a slash, then concatenating the "name"
// field. // field.
{ {