From dbb7b5f8e217440eb0af0c45d3bfc8333534e785 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Sat, 6 Aug 2022 22:28:45 +0200 Subject: [PATCH] fix: g++ C++20 warnings #3734 --- Foundation/include/Poco/Semaphore_POSIX.h | 9 +++++---- Foundation/src/MD4Engine.cpp | 10 ++++++++-- Foundation/src/MD5Engine.cpp | 10 ++++++++-- Foundation/src/SHA1Engine.cpp | 7 +++++++ Foundation/testsuite/src/RWLockTest.cpp | 23 +++++++++++++++++++++-- Foundation/testsuite/src/StringTest.h | 2 ++ 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/Foundation/include/Poco/Semaphore_POSIX.h b/Foundation/include/Poco/Semaphore_POSIX.h index 841f0a702..30ba2abbc 100644 --- a/Foundation/include/Poco/Semaphore_POSIX.h +++ b/Foundation/include/Poco/Semaphore_POSIX.h @@ -22,6 +22,7 @@ #include "Poco/Exception.h" #include #include +#include namespace Poco { @@ -37,10 +38,10 @@ protected: bool waitImpl(long milliseconds); private: - volatile int _n; - int _max; - pthread_mutex_t _mutex; - pthread_cond_t _cond; + std::atomic _n; + int _max; + pthread_mutex_t _mutex; + pthread_cond_t _cond; }; diff --git a/Foundation/src/MD4Engine.cpp b/Foundation/src/MD4Engine.cpp index 02d37a03c..434c46a06 100644 --- a/Foundation/src/MD4Engine.cpp +++ b/Foundation/src/MD4Engine.cpp @@ -129,10 +129,16 @@ const DigestEngine::Digest& MD4Engine::digest() /* Store state in digest */ unsigned char digest[16]; - encode(digest, _context.state, 16); + encode(digest, _context.state, sizeof(digest)); _digest.clear(); +#if defined(POCO_COMPILER_GCC) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif _digest.insert(_digest.begin(), digest, digest + sizeof(digest)); - +#if defined(POCO_COMPILER_GCC) + #pragma GCC diagnostic pop +#endif /* Zeroize sensitive information. */ std::memset(&_context, 0, sizeof (_context)); reset(); diff --git a/Foundation/src/MD5Engine.cpp b/Foundation/src/MD5Engine.cpp index 8ba995842..c780a1480 100644 --- a/Foundation/src/MD5Engine.cpp +++ b/Foundation/src/MD5Engine.cpp @@ -129,10 +129,16 @@ const DigestEngine::Digest& MD5Engine::digest() /* Store state in digest */ unsigned char digest[16]; - encode(digest, _context.state, 16); + encode(digest, _context.state, sizeof(digest)); _digest.clear(); +#if defined(POCO_COMPILER_GCC) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif _digest.insert(_digest.begin(), digest, digest + sizeof(digest)); - +#if defined(POCO_COMPILER_GCC) + #pragma GCC diagnostic pop +#endif /* Zeroize sensitive information. */ std::memset(&_context, 0, sizeof (_context)); reset(); diff --git a/Foundation/src/SHA1Engine.cpp b/Foundation/src/SHA1Engine.cpp index 71fe2d857..2e4d68727 100644 --- a/Foundation/src/SHA1Engine.cpp +++ b/Foundation/src/SHA1Engine.cpp @@ -143,7 +143,14 @@ const DigestEngine::Digest& SHA1Engine::digest() for (count = 0; count < DIGEST_SIZE; count++) hash[count] = (BYTE) ((_context.digest[count>>2]) >> (8*(3-(count & 0x3)))) & 0xff; _digest.clear(); +#if defined(POCO_COMPILER_GCC) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif _digest.insert(_digest.begin(), hash, hash + DIGEST_SIZE); +#if defined(POCO_COMPILER_GCC) + #pragma GCC diagnostic pop +#endif reset(); return _digest; } diff --git a/Foundation/testsuite/src/RWLockTest.cpp b/Foundation/testsuite/src/RWLockTest.cpp index 98e7244e1..afdd6a271 100644 --- a/Foundation/testsuite/src/RWLockTest.cpp +++ b/Foundation/testsuite/src/RWLockTest.cpp @@ -14,6 +14,7 @@ #include "Poco/RWLock.h" #include "Poco/Thread.h" #include "Poco/Runnable.h" +#include using Poco::RWLock; @@ -24,7 +25,12 @@ using Poco::Runnable; class RWLockRunnable: public Runnable { public: - RWLockRunnable(RWLock& lock, volatile int& counter): _lock(lock), _counter(counter), _ok(true) +#ifdef __cpp_lib_atomic_ref + RWLockRunnable(RWLock& lock, int& counter): +#else + RWLockRunnable(RWLock& lock, volatile int& counter): +#endif + _lock(lock), _counter(counter), _ok(true) { } @@ -65,7 +71,11 @@ public: private: RWLock& _lock; +#ifdef __cpp_lib_atomic_ref + std::atomic_ref _counter; +#else volatile int& _counter; +#endif bool _ok; }; @@ -73,7 +83,12 @@ private: class RWTryLockRunnable: public Runnable { public: - RWTryLockRunnable(RWLock& lock, volatile int& counter): _lock(lock), _counter(counter), _ok(true) +#ifdef __cpp_lib_atomic_ref + RWTryLockRunnable(RWLock& lock, int& counter): +#else + RWTryLockRunnable(RWLock& lock, volatile int& counter): +#endif + _lock(lock), _counter(counter), _ok(true) { } @@ -114,7 +129,11 @@ public: private: RWLock& _lock; +#ifdef __cpp_lib_atomic_ref + std::atomic_ref _counter; +#else volatile int& _counter; +#endif bool _ok; }; diff --git a/Foundation/testsuite/src/StringTest.h b/Foundation/testsuite/src/StringTest.h index 84ef9b4c2..1de335301 100644 --- a/Foundation/testsuite/src/StringTest.h +++ b/Foundation/testsuite/src/StringTest.h @@ -77,7 +77,9 @@ private: { T result = 0; if (123 <= std::numeric_limits::max()) + { assertTrue (Poco::strToInt("123", result, 10)); assertTrue (result == 123); + } assertTrue (Poco::strToInt("0", result, 10)); assertTrue (result == 0); assertTrue (Poco::strToInt("000", result, 10)); assertTrue (result == 0);