Patching Dec 9, 2021 6-7a CST- All GitLab services may be unavailable for 5-10 minutes

Commit ca5cc7cf authored by Roland Haas's avatar Roland Haas
Browse files

mpitar: work around overzealous compiler warnings about truncation

parent cbb3ef07
......@@ -226,6 +226,8 @@ void tarentry::make_ustar_header_block(ustar_hdr &hdr, const int xtype,
memset(&hdr, 0, BLOCKSIZE);
if(S_ISLNK(statbuf.st_mode))
{
// TODO: maybe look up how PAX handles long link names
assert(strlen(ln) <= sizeof(hdr.linkname));
strncpy(hdr.linkname, ln, sizeof(hdr.linkname));
hdr.linkname[statbuf.st_size] = '\0';
}
......@@ -270,7 +272,14 @@ void tarentry::make_ustar_header_block(ustar_hdr &hdr, const int xtype,
snprintf(hdr.devminor, sizeof(hdr.devminor), "%0*o",
(int)sizeof(hdr.devminor)-1, 0);
}
strncpy(hdr.name, filename, sizeof(hdr.name));
// this is functionally identical to what strncpy alreday does but avoids
// warnings from over-eager compilers about possible string truncation (given
// that I am using strncpy exactly as designed this is just sad).
if(strlen(filename) <= sizeof(hdr.name)) {
strncpy(hdr.name, filename, sizeof(hdr.name));
} else {
memcpy(hdr.name, filename, sizeof(hdr.name));
}
unsigned long int checksum = 0;
for(size_t j = 0 ; j < sizeof(hdr) ; j++)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment