From be420e7a7143d0fe7da8170b517c20a0fab81598 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> 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 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/fileFormats/ensight/file/ensightFile.C b/src/fileFormats/ensight/file/ensightFile.C index dd4bdeb4b61..4cdb931fffd 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 9a4310711b8..014dc2d527b 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<vector>::nComponents; ++cmpt) + direction minCmpt = 0; + scalar minMag = mag(nf[minCmpt]); + for (direction cmpt = 1; cmpt < pTraits<vector>::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<Pair<label>> indexPairs(this->size(), Pair<label>(Zero, Zero)); - // Virtual turbulence plane indices - label j = 0; - label k = 0; - forAll(*this, facei) { const scalar& centre0 = localPos[facei][0]; const scalar& centre1 = localPos[facei][1]; - j = label((centre0 - localMinPt[0])*invDelta_[0]); - k = label((centre1 - localMinPt[1])*invDelta_[1]); + // Virtual turbulence plane indices + const label j = label((centre0 - localMinPt[0])*invDelta_[0]); + const label k = label((centre1 - localMinPt[1])*invDelta_[1]); indexPairs[facei] = Pair<label>(facei, k*n[0] + j); } -- GitLab