diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/include/kf/ASimpleString.h b/include/kf/ASimpleString.h index be7c845..e5de679 100644 --- a/include/kf/ASimpleString.h +++ b/include/kf/ASimpleString.h @@ -5,7 +5,6 @@ namespace kf { - using namespace std; /////////////////////////////////////////////////////////////////////////////////////////////////// // ASimpleString - non-owning string for NT kernel, inspired by http://docs.oracle.com/javase/7/docs/api/java/lang/String.html @@ -17,7 +16,7 @@ namespace kf ASimpleString(); template - ASimpleString(span buffer); + ASimpleString(std::span buffer); ASimpleString(_In_ const ANSI_STRING& str) { @@ -185,7 +184,7 @@ namespace kf } template - inline ASimpleString::ASimpleString(span buffer) + inline ASimpleString::ASimpleString(std::span buffer) { setString(const_cast(reinterpret_cast(buffer.data())), static_cast(buffer.size_bytes())); } diff --git a/include/kf/ArrayUtils.h b/include/kf/ArrayUtils.h index 5a95894..4801e10 100644 --- a/include/kf/ArrayUtils.h +++ b/include/kf/ArrayUtils.h @@ -3,7 +3,6 @@ namespace kf { - using namespace std; template inline constexpr std::array makeArrayOfBytes(Ts&&... args) noexcept diff --git a/include/kf/Base64.h b/include/kf/Base64.h index f9317c1..dd93c4d 100644 --- a/include/kf/Base64.h +++ b/include/kf/Base64.h @@ -4,7 +4,6 @@ namespace kf { - using namespace std; // original implementation is taken from https://github.com/adamvr/arduino-base64/blob/master/Base64.cpp @@ -33,7 +32,7 @@ namespace kf return ((6 * input.charLength()) / 8) - numEq; } - static int decode(const USimpleString& input, span output) + static int decode(const USimpleString& input, std::span output) { int inputIdx = 0; int a4Idx = 0; diff --git a/include/kf/EarlyAllocator.h b/include/kf/EarlyAllocator.h index ff5a5ec..9542d6e 100644 --- a/include/kf/EarlyAllocator.h +++ b/include/kf/EarlyAllocator.h @@ -2,18 +2,17 @@ namespace kf { - using namespace std; template class EarlyAllocator { public: - static_assert(!is_const_v, "The C++ Standard forbids containers of const elements because allocator is ill-formed."); + static_assert(!std::is_const_v, "The C++ Standard forbids containers of const elements because allocator is ill-formed."); using value_type = T; using size_type = size_t; using difference_type = ptrdiff_t; - using propagate_on_container_move_assignment = true_type; + using propagate_on_container_move_assignment = std::true_type; constexpr EarlyAllocator() noexcept = default; @@ -33,10 +32,7 @@ namespace kf template T* initialize(const size_t count) noexcept { - if (m_ptr || m_size) - { - _Xinvalid_argument("m_ptr || m_size"); - } + ASSERT(!(m_ptr || m_size)); m_size = count * sizeof(T); m_ptr = static_cast(operator new(m_size, poolType)); @@ -46,10 +42,7 @@ namespace kf void deallocate(const T* ptr, const size_t count) noexcept { - if (ptr != m_ptr || count * sizeof(T) > m_size) - { - _Xinvalid_argument("ptr != m_ptr || count * sizeof(T) > m_size"); - } + ASSERT(ptr == m_ptr && count * sizeof(T) <= m_size); operator delete(m_ptr); m_ptr = nullptr; @@ -58,10 +51,7 @@ namespace kf _NODISCARD T* allocate(const size_t count) noexcept { - if (!m_ptr || count * sizeof(T) > m_size) - { - _Xinvalid_argument("!m_ptr || count * sizeof(T) > m_size"); - } + ASSERT(m_ptr && count * sizeof(T) <= m_size); return m_ptr; } diff --git a/include/kf/EncodingDetector.h b/include/kf/EncodingDetector.h index 0051dc6..cea28a9 100644 --- a/include/kf/EncodingDetector.h +++ b/include/kf/EncodingDetector.h @@ -4,7 +4,6 @@ namespace kf { - using namespace std; ////////////////////////////////////////////////////////////////////////////////// // EncodingDetector class identifies the encoding of a buffer. @@ -13,7 +12,7 @@ namespace kf class EncodingDetector { public: - EncodingDetector(span buffer); + EncodingDetector(std::span buffer); enum Encoding { @@ -33,15 +32,15 @@ namespace kf enum { kMinimalBufferSize = kMaximumBomLength }; private: - bool detectBom(span bomBytes); - bool detectUtf16(span buffer); + bool detectBom(std::span bomBytes); + bool detectUtf16(std::span buffer); private: Encoding m_encoding = Unknown; int m_bomLength = 0; }; - inline EncodingDetector::EncodingDetector(span buffer) : m_encoding(), m_bomLength() + inline EncodingDetector::EncodingDetector(std::span buffer) : m_encoding(), m_bomLength() { if (buffer.size() < kMinimalBufferSize) { @@ -62,7 +61,7 @@ namespace kf m_encoding = ANSI; } - inline bool EncodingDetector::detectBom(span bomBytes) + inline bool EncodingDetector::detectBom(std::span bomBytes) { if (bomBytes[0] == std::byte(0xff) && bomBytes[1] == std::byte(0xfe) && (bomBytes[2] != std::byte(0) || bomBytes[3] != std::byte(0))) { @@ -102,7 +101,7 @@ namespace kf return false; } - inline bool EncodingDetector::detectUtf16(span buffer) + inline bool EncodingDetector::detectUtf16(std::span buffer) { int zeros[2] = {}; diff --git a/include/kf/Hex.h b/include/kf/Hex.h index aa0ec1a..4aedc8b 100644 --- a/include/kf/Hex.h +++ b/include/kf/Hex.h @@ -6,7 +6,6 @@ namespace kf { - using namespace std; //////////////////////////////////////////////////////////////////////////// // The Hex class provides functionality to encode binary data into hexadecimal string representation @@ -14,12 +13,12 @@ namespace kf class Hex { public: - static int encodeLen(span input) + static int encodeLen(std::span input) { return static_cast(input.size() * 2); } - static bool encode(span input, _Out_ USimpleString& output) + static bool encode(std::span input, _Out_ USimpleString& output) { if (output.maxByteLength() < encodeLen(input)) { @@ -40,7 +39,7 @@ namespace kf return true; } - static int decodeLen(span input) + static int decodeLen(std::span input) { return static_cast(input.size() / 2); } @@ -50,7 +49,7 @@ namespace kf return input.charLength() / 2; } - static bool decode(const ASimpleString& input, _Out_ span& output) + static bool decode(const ASimpleString& input, _Out_ std::span& output) { if (output.size() != static_cast(decodeLen(input))) { @@ -74,14 +73,14 @@ namespace kf private: static inline const char kHexArray[] = "0123456789ABCDEF"; - static array toHex(uint8_t b) + static std::array toHex(uint8_t b) { return { static_cast(kHexArray[b >> 4]), static_cast(kHexArray[b & 0xF]) }; } - static int fromHex(const array& hexByte) + static int fromHex(const std::array& hexByte) { - array digits; + std::array digits; for (int i = 0; i < 2; ++i) { diff --git a/include/kf/Scanner.h b/include/kf/Scanner.h index ce4ff39..a641171 100644 --- a/include/kf/Scanner.h +++ b/include/kf/Scanner.h @@ -5,12 +5,11 @@ namespace kf { - using namespace std; class Scanner { public: - Scanner(span data) : m_data(data) + Scanner(std::span data) : m_data(data) { } @@ -70,6 +69,6 @@ namespace kf } private: - span m_data; + std::span m_data; }; } diff --git a/include/kf/TextDetector.h b/include/kf/TextDetector.h index 3e16a74..b959b0f 100644 --- a/include/kf/TextDetector.h +++ b/include/kf/TextDetector.h @@ -7,7 +7,6 @@ namespace kf { - using namespace std; /////////////////////////////////////////////////////////////////////////////////////////////////// // TextDetector class provides a utility to determine whether a given buffer contains textual data. @@ -16,7 +15,7 @@ namespace kf class TextDetector { public: - static bool isText(span buffer) + static bool isText(std::span buffer) { EncodingDetector encodingDetector(buffer); @@ -62,15 +61,15 @@ namespace kf } template - static bool isValidTextLE(span buffer) + static bool isValidTextLE(std::span buffer) { - return ranges::none_of(buffer, [](auto ch) { return isInvalidChar(ch); }); + return std::ranges::none_of(buffer, [](auto ch) { return isInvalidChar(ch); }); } template - static bool isValidTextBE(span buffer) + static bool isValidTextBE(std::span buffer) { - return ranges::none_of(buffer, [](auto ch) { return isInvalidChar(swapBytes(ch)); }); + return std::ranges::none_of(buffer, [](auto ch) { return isInvalidChar(swapBytes(ch)); }); } }; } diff --git a/include/kf/USimpleString.h b/include/kf/USimpleString.h index 86cc71e..70a15d8 100644 --- a/include/kf/USimpleString.h +++ b/include/kf/USimpleString.h @@ -5,7 +5,6 @@ namespace kf { - using namespace std; /////////////////////////////////////////////////////////////////////////////////////////////////// // USimpleString - non-owning string for NT kernel, inspired by http://docs.oracle.com/javase/7/docs/api/java/lang/String.html @@ -21,7 +20,7 @@ namespace kf USimpleString(_In_reads_bytes_(byteLength) const void* buffer, _In_ int byteLength); template - USimpleString(span buffer); + USimpleString(std::span buffer); USimpleString(_Inout_ USimpleString&& another); USimpleString(_In_ const USimpleString& another); @@ -126,7 +125,7 @@ namespace kf int copyTo(_In_ int maxCharLength, _Out_cap_(maxCharLength) WCHAR* destination) const { - const int charsToCopy = min(maxCharLength - 1, charLength()); + const int charsToCopy = (std::min)(maxCharLength - 1, charLength()); if (charsToCopy >= 0) { @@ -200,7 +199,7 @@ namespace kf } template - inline USimpleString::USimpleString(span buffer) + inline USimpleString::USimpleString(std::span buffer) { setString(const_cast(reinterpret_cast(buffer.data())), static_cast(buffer.size_bytes())); } diff --git a/include/kf/ext/timsort.h b/include/kf/ext/timsort.h index 12963ad..6a11c7d 100644 --- a/include/kf/ext/timsort.h +++ b/include/kf/ext/timsort.h @@ -38,7 +38,6 @@ namespace timsort { namespace detail { - using namespace std; template inline int cmp(const T& lhs, const T& rhs) @@ -101,7 +100,7 @@ namespace timsort inline int compute_minrun(const uint64_t size) { const int top_bit = 64 - clzll(size); - const int shift = max(top_bit, 6) - 6; + const int shift = (std::max)(top_bit, 6) - 6; const int minrun = static_cast(size >> shift); const uint64_t mask = (1ULL << shift) - 1; @@ -218,7 +217,7 @@ namespace timsort return; } - swap(dst[start], dst[end]); + std::swap(dst[start], dst[end]); start++; end--; } @@ -238,7 +237,7 @@ namespace timsort { if (cmp(dst[size - 2], dst[size - 1]) > 0) { - swap(dst[size - 2], dst[size - 1]); + std::swap(dst[size - 2], dst[size - 1]); } return 2; @@ -350,7 +349,7 @@ namespace timsort const size_t B = stack[stack_curr - 1].length; const size_t curr = stack[stack_curr - 2].start; size_t i, j, k; - tim_sort_resize(store, min(A, B)); + tim_sort_resize(store, (std::min)(A, B)); T* storage = store->storage; /* left merge */