COMP: gcc-12 buffer check bypasses xsputn (#2481, #2496)

- add overflow() method to the SHA1 streambuf. Previously could rely
  on xsputn for adding to sha1 content, but streams now check pptr()
  first to test for the buffering range and thus overflow() is needed.
This commit is contained in:
Mark Olesen
2022-06-03 08:52:58 +02:00
parent 6f4196ae62
commit 91198eaf6a
3 changed files with 23 additions and 7 deletions

View File

@ -32,8 +32,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef OSHA1stream_H
#define OSHA1stream_H
#ifndef Foam_OSHA1stream_H
#define Foam_OSHA1stream_H
#include "OSstream.H"
#include "SHA1.H"
@ -63,10 +63,17 @@ class osha1stream
protected:
//- Handle overflow
virtual int overflow(int c = EOF)
{
if (c != EOF) sha1_.append(c);
return c;
}
//- Put sequence of characters
virtual std::streamsize xsputn(const char* s, std::streamsize n)
{
sha1_.append(s, n);
if (n) sha1_.append(s, n);
return n;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -42,8 +42,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef SHA1_H
#define SHA1_H
#ifndef Foam_SHA1_H
#define Foam_SHA1_H
#include <string>
#include <cstdint>
@ -113,6 +113,9 @@ public:
//- Reset the hashed data before appending more
void clear() noexcept;
//- Append single character
inline void append(char c);
//- Append data for processing
inline SHA1& append(const char* str);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -52,6 +52,12 @@ inline Foam::SHA1::SHA1(const std::string& str)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline void Foam::SHA1::append(char c)
{
processBytes(&c, 1);
}
inline Foam::SHA1& Foam::SHA1::append(const char* data, size_t len)
{
processBytes(data, len);