Skip to content

Commit

Permalink
Fortify uses of std::min/max against Windows
Browse files Browse the repository at this point in the history
In public headers it's better to add parentheses around std::min/max
because on Windows, these can be treated as the (in)famous min/max
macros from Windows SDK (minwindef.h) if the user doesn't define
NOMINMAX.
  • Loading branch information
MiKom committed Oct 29, 2024
1 parent 5019ab2 commit 362100d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cpp/duplicatetracker/include/duplicatetracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class DuplicateTrackerBase :

explicit DuplicateTrackerBase(std::size_t numBuckets, const Hash &h, const Equal &e)
#ifdef __cpp_lib_memory_resource
: Base(this->m_buffer, sizeof(this->m_buffer), std::max(numBuckets, Prealloc), h, e){}
: Base(this->m_buffer, sizeof(this->m_buffer), (std::max)(numBuckets, Prealloc), h, e){}
#else
: Base(std::max(numBuckets, Prealloc), h, e)
: Base((std::max)(numBuckets, Prealloc), h, e)
{
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion qt/KDStlContainerAdaptor/KDStlContainerAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ struct StdVectorAdaptor : std::vector<T, Args...>

if (len < 0)
len = s;
len = std::min(len, s - pos);
len = (std::min)(len, s - pos);

const auto b = this->begin() + pos;
const auto e = b + len;
Expand Down

0 comments on commit 362100d

Please sign in to comment.