diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-11-05 03:40:06 +0300 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-11-05 18:16:16 +0300 |
commit | afb3b347d50128b80c568743292583329ac6fca3 (patch) | |
tree | a08eb05bca5115548dc19dbbeab92a45310f01c4 | |
parent | 8b10115479c20e7f56f5fb438bcfe6151ef9e062 (diff) |
Suppress a 'helpful' GCC warning for some correct code
-rw-r--r-- | src/microtar.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/microtar.c b/src/microtar.c index e02cf5d..1f22c19 100644 --- a/src/microtar.c +++ b/src/microtar.c @@ -213,9 +213,23 @@ static int header_to_raw(char* raw, const mtar_header_t* h) return rc; raw[TYPE_OFF] = h->type ? h->type : MTAR_TREG; + +#ifdef __GNUC__ +/* Sigh. GCC wrongly assumes the output of strncpy() is supposed to be + * a null-terminated string -- which it is not, and we are relying on + * that fact here -- and tries to warn about 'string truncation' because + * the null terminator might not be copied. Just suppress the warning. */ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif + strncpy(&raw[NAME_OFF], h->name, NAME_LEN); strncpy(&raw[LINKNAME_OFF], h->linkname, LINKNAME_LEN); +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif + /* Calculate and write checksum */ chksum = checksum(raw); if((rc = print_octal(&raw[CHKSUM_OFF], CHKSUM_LEN-1, chksum))) |