From 7360ef7d46bfaaeefbb7acd4eca31fe81b662129 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 8 Jul 2019 13:53:06 +0200 Subject: [PATCH] COMP: silence spurious GCC -Wstringop-truncation warning in ensightFile --- src/fileFormats/ensight/file/ensightFile.C | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fileFormats/ensight/file/ensightFile.C b/src/fileFormats/ensight/file/ensightFile.C index 8f9b28d555..ac552d911d 100644 --- a/src/fileFormats/ensight/file/ensightFile.C +++ b/src/fileFormats/ensight/file/ensightFile.C @@ -165,8 +165,15 @@ Foam::Ostream& Foam::ensightFile::write Foam::Ostream& Foam::ensightFile::write(const char* value) { + // Parentheses around strncpy to silence the GCC -Wstringop-truncation + // warning, which is spurious here. + // The max-size and buffer-size *are* identical, which means the buffer + // may not have a nul terminator. However, this is properly handled in + // the subsequent binary write and the ASCII write explicitly adds + // a nul terminator. + char buf[80]; - strncpy(buf, value, 80); // max 80 chars or padded with nul if smaller + (strncpy(buf, value, 80)); // max 80 chars or padded with nul if smaller if (format() == IOstream::BINARY) {