Common: Enforce explicit handle validation

Some invalid handle values are -1 or INVALID_HANDLE_VALUE, hence our
handle template has a specific invalid handle value parameter we should
always test against. Time and again, I find my code simply comparing
handle against zero.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2025-07-08 11:17:16 +02:00
parent a9d87b4cfd
commit b99b2fc19e
2 changed files with 7 additions and 0 deletions

View File

@ -2383,6 +2383,9 @@ namespace stdex
socket(_In_ const socket& other);
socket& operator =(_In_ const socket& other);
// Force use of valid() method when testing handle.
operator bool() const;
public:
socket(_Inout_ socket&& other) noexcept : m_h(other.m_h)
{

View File

@ -200,6 +200,10 @@ namespace stdex
///
operator T() const noexcept { return m_h; }
private:
// Force use of valid() method when testing handle.
operator bool() const;
protected:
T m_h;
};