Skip to content

Commit 6194bb6

Browse files
committed
fix: compilation warnings
1 parent a20fab9 commit 6194bb6

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

include/dynlibutils/memaddr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CMemory
112112

113113
// Addition and subtraction operators.
114114
CMemory operator+(const std::size_t right) const noexcept { return Offset(right); }
115-
CMemory operator-(const std::size_t right) const noexcept { return Offset(-right); }
115+
CMemory operator-(const std::size_t right) const noexcept { return Offset(-static_cast<std::ptrdiff_t>(right)); }
116116
CMemory operator+(const std::ptrdiff_t right) const noexcept { return Offset(right); }
117117
CMemory operator-(const std::ptrdiff_t right) const noexcept { return Offset(-right); }
118118
CMemory operator+(const CMemory right) const noexcept { return Offset(static_cast<std::ptrdiff_t>(right.m_addr)); }

include/dynlibutils/module.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,23 @@ concept PatternCallback_t = requires(T func, std::size_t index, CMemory match)
8383
# define PatternCallback_t typename
8484
#endif
8585

86+
#if defined(__clang__)
87+
# define DYNLIB_FORCE_INLINE [[gnu::always_inline]] [[gnu::gnu_inline]] extern inline
88+
# define DYNLIB_NOINLINE [[gnu::noinline]]
89+
#elif defined(__GNUC__)
90+
# define DYNLIB_FORCE_INLINE [[gnu::always_inline]] inline
91+
# define DYNLIB_NOINLINE [[gnu::noinline]]
92+
#elif defined(_MSC_VER)
93+
# pragma warning(error: 4714)
94+
# define DYNLIB_FORCE_INLINE [[msvc::forceinline]]
95+
# define DYNLIB_NOINLINE __declspec(noinline)
96+
#else
97+
# define DYNLIB_FORCE_INLINE inline
98+
# define DYNLIB_NOINLINE
99+
#endif
100+
86101
template<std::size_t INDEX = 0, std::size_t N, std::size_t SIZE = (N - 1) / 2>
87-
[[always_inline, nodiscard]]
88-
inline DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[N], std::size_t& n, std::size_t& nIndex, std::array<std::uint8_t, SIZE>& aBytes, std::array<char, SIZE>& aMask)
102+
DYNLIB_FORCE_INLINE DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[N], std::size_t& n, std::size_t& nIndex, std::array<std::uint8_t, SIZE>& aBytes, std::array<char, SIZE>& aMask)
89103
{
90104
static_assert(SIZE > 0, "Process pattern cannot be empty");
91105

@@ -172,8 +186,7 @@ inline DYNLIB_COMPILE_TIME_EXPR void ProcessStringPattern(const char (&szInput)[
172186
// Output : Pattern_t<SIZE> (fixed-size array by N cells with mask and used size)
173187
//----------------------------------------------------------------------------
174188
template<std::size_t N, std::size_t SIZE = (N - 1) / 2>
175-
[[always_inline, nodiscard]]
176-
inline DYNLIB_COMPILE_TIME_EXPR auto ParseStringPattern(const char (&szInput)[N])
189+
[[nodiscard]] DYNLIB_FORCE_INLINE DYNLIB_COMPILE_TIME_EXPR auto ParseStringPattern(const char (&szInput)[N])
177190
{
178191
static_assert(SIZE > 0, "Pattern cannot be empty");
179192

include/dynlibutils/vthook.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class VirtualUnprotector final
8181
m_nLength = nLength;
8282
m_pTarget = pTarget;
8383

84-
bool bIsUnprotected = VirtualProtect(pTarget, nLength, PAGE_EXECUTE_READWRITE, &m_nOldProtect);
84+
[[maybe_unused]] bool bIsUnprotected = VirtualProtect(pTarget, nLength, PAGE_EXECUTE_READWRITE, &m_nOldProtect);
8585
#else
8686
long pageSize = sysconf(_SC_PAGESIZE);
8787

@@ -117,9 +117,9 @@ class VirtualUnprotector final
117117
{
118118
#if _WIN32
119119
DWORD origProtect;
120-
bool bIsUnprotected = VirtualProtect(m_pTarget, m_nLength, m_nOldProtect, &origProtect);
120+
[[maybe_unused]] bool bIsUnprotected = VirtualProtect(m_pTarget, m_nLength, m_nOldProtect, &origProtect);
121121
#else
122-
bool bIsUnprotected = !mprotect(m_pTarget, m_nLength, m_nOldProtect);
122+
[[maybe_unused]] bool bIsUnprotected = !mprotect(m_pTarget, m_nLength, m_nOldProtect);
123123
#endif
124124

125125
assert(bIsUnprotected);
@@ -507,8 +507,8 @@ class CVTHookAutoBase<T, METHOD> : public T<R, C*, Args...>
507507
using CBase = T<R, C*, Args...>;
508508
using CBase::CBase;
509509

510-
[[ always_inline ]] // Wend4r (Linux): don't allow typeinfo/rtti to be generated for templated C argument.
511-
void Hook(CVirtualTable pVTable, typename CBase::Function_t &&func) noexcept
510+
// Wend4r (Linux): don't allow typeinfo/rtti to be generated for templated C argument.
511+
DYNLIB_FORCE_INLINE void Hook(CVirtualTable pVTable, typename CBase::Function_t &&func) noexcept
512512
{
513513
CBase::Hook(pVTable, GetVirtualIndex<METHOD>(), std::move(func));
514514
}

0 commit comments

Comments
 (0)