diff options
author | Jeffrey Walton <noloader@gmail.com> | 2017-08-18 07:59:21 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2017-08-18 07:59:21 -0400 |
commit | 42b7c4ea5673430eb1599a666b3b5c610638fbaf (patch) | |
tree | a7df2e51826ad4e6e6e3f95e5941dd4d0892d4c3 /secblock.h | |
parent | b61953a7a7f7a55849203f81ca8ae39c5c04ab8f (diff) | |
download | cryptopp-git-42b7c4ea5673430eb1599a666b3b5c610638fbaf.tar.gz |
Clear Coverity finding CONSTANT_EXPRESSION_RESULT (CID 182772)
This may create a MSC warning about a conditional expression being constant
Diffstat (limited to 'secblock.h')
-rw-r--r-- | secblock.h | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -99,11 +99,15 @@ protected: //! because the latter is not a constexpr. Some compilers, like Clang, do not
//! optimize it well under all circumstances. Compilers like GCC, ICC and MSVC appear
//! to optimize it well in either form.
+ //! \details The <tt>sizeof(T) != 1</tt> in the condition attempts to help the
+ //! compiler optimize the check for byte types. Coverity findings for
+ //! CONSTANT_EXPRESSION_RESULT were generated without it. For byte types,
+ //! size never exceeded ELEMS_MAX but the code was not removed.
//! \note size is the count of elements, and not the number of bytes
static void CheckSize(size_t size)
{
// C++ throws std::bad_alloc (C++03) or std::bad_array_new_length (C++11) here.
- if (size > ELEMS_MAX)
+ if (sizeof(T) != 1 && size > ELEMS_MAX)
throw InvalidArgument("AllocatorBase: requested size would cause integer overflow");
}
};
|