From d3bcc71b6490c5d120a3b7ea2e7dce8d9fded28c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 31 Jan 2020 12:08:31 +0100 Subject: [PATCH] COMP: avoid -Wstringop-truncation warning - the gcc c++/9 includes now inline strncpy, which obliterates the previous method of suppressing the warning. Now simply allocate additional space for the nul character. COMP: silence some icc warnings --- src/fileFormats/ensight/file/ensightFile.C | 14 +++++-------- ...lentDigitalFilterInletFvPatchVectorField.C | 21 ++++++++----------- .../schemes/weightedFlux/weightedFlux.H | 2 +- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/fileFormats/ensight/file/ensightFile.C b/src/fileFormats/ensight/file/ensightFile.C index dd4bdeb4b6..4cdb931fff 100644 --- a/src/fileFormats/ensight/file/ensightFile.C +++ b/src/fileFormats/ensight/file/ensightFile.C @@ -166,19 +166,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. + // Output 80 chars, but allocate for trailing nul character + // to avoid -Wstringop-truncation warnings/errors. - char buf[80]; - (strncpy(buf, value, 80)); // max 80 chars or padded with nul if smaller + char buf[80+1]; + strncpy(buf, value, 80); // max 80 chars or padded with nul if smaller if (format() == IOstream::BINARY) { - write(buf, sizeof(buf)); + write(buf, 80); } else { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchVectorField.C index 9a4310711b..014dc2d527 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDigitalFilterInlet/turbulentDigitalFilterInletFvPatchVectorField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -96,11 +96,11 @@ Foam::turbulentDigitalFilterInletFvPatchVectorField::patchIndexPairs() const vector nf(computePatchNormal()); // Find the second local coordinate direction - direction minCmpt = -1; - scalar minMag = VGREAT; - for (direction cmpt = 0; cmpt < pTraits::nComponents; ++cmpt) + direction minCmpt = 0; + scalar minMag = mag(nf[minCmpt]); + for (direction cmpt = 1; cmpt < pTraits::nComponents; ++cmpt) { - scalar s = mag(nf[cmpt]); + const scalar s = mag(nf[cmpt]); if (s < minMag) { minMag = s; @@ -110,7 +110,7 @@ Foam::turbulentDigitalFilterInletFvPatchVectorField::patchIndexPairs() // Create the second local coordinate direction vector e2(Zero); - e2[minCmpt] = 1.0; + e2[minCmpt] = 1; // Remove normal component e2 -= (nf&e2)*nf; @@ -147,17 +147,14 @@ Foam::turbulentDigitalFilterInletFvPatchVectorField::patchIndexPairs() // Compute virtual-actual patch index pairs List> indexPairs(this->size(), Pair