From e96db1e03202975b831853c3b598e3717881f27d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 2 Sep 2019 08:30:06 -0400 Subject: [PATCH 1/2] General: Use explicit where applicable Makes conversions explicit in order to prevent error-prone implicit conversions. --- include/kabufuda/AsyncIO.hpp | 6 +++--- include/kabufuda/Card.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/kabufuda/AsyncIO.hpp b/include/kabufuda/AsyncIO.hpp index 21f0505..63f1091 100644 --- a/include/kabufuda/AsyncIO.hpp +++ b/include/kabufuda/AsyncIO.hpp @@ -28,7 +28,7 @@ class AsyncIO { public: AsyncIO() = default; - AsyncIO(SystemStringView filename, bool truncate = false); + explicit AsyncIO(SystemStringView filename, bool truncate = false); ~AsyncIO(); AsyncIO(AsyncIO&& other); AsyncIO& operator=(AsyncIO&& other); @@ -41,9 +41,9 @@ public: ECardResult pollStatus() const; void waitForCompletion() const; #ifndef _WIN32 - operator bool() const { return m_fd != -1; } + explicit operator bool() const { return m_fd != -1; } #else - operator bool() const { return m_fh != INVALID_HANDLE_VALUE; } + explicit operator bool() const { return m_fh != INVALID_HANDLE_VALUE; } #endif }; diff --git a/include/kabufuda/Card.hpp b/include/kabufuda/Card.hpp index 6b913db..035cb1b 100644 --- a/include/kabufuda/Card.hpp +++ b/include/kabufuda/Card.hpp @@ -24,7 +24,7 @@ class FileHandle { public: FileHandle() = default; uint32_t getFileNo() const { return idx; } - operator bool() const { return getFileNo() != UINT32_MAX; } + explicit operator bool() const { return getFileNo() != UINT32_MAX; } }; struct ProbeResults { @@ -136,7 +136,7 @@ public: * @param game The game code. * @param maker The maker code. */ - Card(const char* game = nullptr, const char* maker = nullptr); + explicit Card(const char* game = nullptr, const char* maker = nullptr); ~Card(); /** @@ -489,6 +489,6 @@ public: /** * @return Whether or not the card is within a ready state. */ - operator bool() const { return getError() == ECardResult::READY; } + explicit operator bool() const { return getError() == ECardResult::READY; } }; } // namespace kabufuda From 9d3a436e70423c2f8e5e20592d1687ed24f18326 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 2 Sep 2019 08:45:05 -0400 Subject: [PATCH 2/2] Card: Use UINT32_MAX for FileHandle's default initializer Avoids a sign conversion --- include/kabufuda/Card.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/kabufuda/Card.hpp b/include/kabufuda/Card.hpp index 035cb1b..b3fc320 100644 --- a/include/kabufuda/Card.hpp +++ b/include/kabufuda/Card.hpp @@ -17,9 +17,9 @@ namespace kabufuda { class FileHandle { friend class Card; - uint32_t idx = -1; + uint32_t idx = UINT32_MAX; int32_t offset = 0; - FileHandle(uint32_t idx) : idx(idx) {} + explicit FileHandle(uint32_t idx) : idx(idx) {} public: FileHandle() = default;