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
This commit is contained in:
Mark Olesen
2020-01-31 12:08:31 +01:00
parent 370d1a4589
commit d3bcc71b64
3 changed files with 15 additions and 22 deletions

View File

@ -166,19 +166,15 @@ Foam::Ostream& Foam::ensightFile::write
Foam::Ostream& Foam::ensightFile::write(const char* value) Foam::Ostream& Foam::ensightFile::write(const char* value)
{ {
// Parentheses around strncpy to silence the GCC -Wstringop-truncation // Output 80 chars, but allocate for trailing nul character
// warning, which is spurious here. // to avoid -Wstringop-truncation warnings/errors.
// 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]; char buf[80+1];
(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) if (format() == IOstream::BINARY)
{ {
write(buf, sizeof(buf)); write(buf, 80);
} }
else else
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -96,11 +96,11 @@ Foam::turbulentDigitalFilterInletFvPatchVectorField::patchIndexPairs()
const vector nf(computePatchNormal()); const vector nf(computePatchNormal());
// Find the second local coordinate direction // Find the second local coordinate direction
direction minCmpt = -1; direction minCmpt = 0;
scalar minMag = VGREAT; scalar minMag = mag(nf[minCmpt]);
for (direction cmpt = 0; cmpt < pTraits<vector>::nComponents; ++cmpt) for (direction cmpt = 1; cmpt < pTraits<vector>::nComponents; ++cmpt)
{ {
scalar s = mag(nf[cmpt]); const scalar s = mag(nf[cmpt]);
if (s < minMag) if (s < minMag)
{ {
minMag = s; minMag = s;
@ -110,7 +110,7 @@ Foam::turbulentDigitalFilterInletFvPatchVectorField::patchIndexPairs()
// Create the second local coordinate direction // Create the second local coordinate direction
vector e2(Zero); vector e2(Zero);
e2[minCmpt] = 1.0; e2[minCmpt] = 1;
// Remove normal component // Remove normal component
e2 -= (nf&e2)*nf; e2 -= (nf&e2)*nf;
@ -147,17 +147,14 @@ Foam::turbulentDigitalFilterInletFvPatchVectorField::patchIndexPairs()
// Compute virtual-actual patch index pairs // Compute virtual-actual patch index pairs
List<Pair<label>> indexPairs(this->size(), Pair<label>(Zero, Zero)); List<Pair<label>> indexPairs(this->size(), Pair<label>(Zero, Zero));
// Virtual turbulence plane indices
label j = 0;
label k = 0;
forAll(*this, facei) forAll(*this, facei)
{ {
const scalar& centre0 = localPos[facei][0]; const scalar& centre0 = localPos[facei][0];
const scalar& centre1 = localPos[facei][1]; const scalar& centre1 = localPos[facei][1];
j = label((centre0 - localMinPt[0])*invDelta_[0]); // Virtual turbulence plane indices
k = label((centre1 - localMinPt[1])*invDelta_[1]); 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); indexPairs[facei] = Pair<label>(facei, k*n[0] + j);
} }

View File

@ -162,7 +162,7 @@ public:
//- Destructor //- Destructor
~weightedFlux(); virtual ~weightedFlux();
// Member Functions // Member Functions