From fabadaad2ae549825af104d167348ca9d4c164bc Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 11 May 2023 01:17:54 -0500 Subject: [PATCH] Fix const-correctness bugs in uniq_ptr and code that uses it --- src/cbs.cpp | 2 +- src/crypto.cpp | 4 ++-- src/platform/windows/display_vram.cpp | 2 +- src/utility.h | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cbs.cpp b/src/cbs.cpp index 59b58710..52a3ed93 100644 --- a/src/cbs.cpp +++ b/src/cbs.cpp @@ -54,7 +54,7 @@ namespace cbs { }; util::buffer_t - write(const cbs::ctx_t &cbs_ctx, std::uint8_t nal, void *uh, AVCodecID codec_id) { + write(cbs::ctx_t &cbs_ctx, std::uint8_t nal, void *uh, AVCodecID codec_id) { cbs::frag_t frag; auto err = ff_cbs_insert_unit_content(&frag, -1, nal, uh, nullptr); if (err < 0) { diff --git a/src/crypto.cpp b/src/crypto.cpp index 650f2f81..5dec0f8d 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -401,7 +401,7 @@ namespace crypto { sign(const pkey_t &pkey, const std::string_view &data, const EVP_MD *md) { md_ctx_t ctx { EVP_MD_CTX_create() }; - if (EVP_DigestSignInit(ctx.get(), nullptr, md, nullptr, pkey.get()) != 1) { + if (EVP_DigestSignInit(ctx.get(), nullptr, md, nullptr, (EVP_PKEY *) pkey.get()) != 1) { return {}; } @@ -474,7 +474,7 @@ namespace crypto { bool verify(const x509_t &x509, const std::string_view &data, const std::string_view &signature, const EVP_MD *md) { - auto pkey = X509_get_pubkey(x509.get()); + auto pkey = X509_get0_pubkey(x509.get()); md_ctx_t ctx { EVP_MD_CTX_create() }; diff --git a/src/platform/windows/display_vram.cpp b/src/platform/windows/display_vram.cpp index a167c155..376a5852 100644 --- a/src/platform/windows/display_vram.cpp +++ b/src/platform/windows/display_vram.cpp @@ -725,7 +725,7 @@ namespace platf::dxgi { struct encoder_img_ctx_t { // Used to determine if the underlying texture changes. // Not safe for actual use by the encoder! - texture2d_t::pointer capture_texture_p; + texture2d_t::const_pointer capture_texture_p; texture2d_t encoder_texture; shader_res_t encoder_input_res; diff --git a/src/utility.h b/src/utility.h index 34eb366d..3ed32120 100644 --- a/src/utility.h +++ b/src/utility.h @@ -490,6 +490,7 @@ namespace util { public: using element_type = T; using pointer = element_type *; + using const_pointer = element_type const *; using deleter_type = D; constexpr uniq_ptr() noexcept: @@ -563,12 +564,12 @@ namespace util { return _p; } - const pointer + const_pointer get() const { return _p; } - const std::add_lvalue_reference_t + std::add_lvalue_reference_t operator*() const { return *_p; } @@ -576,7 +577,7 @@ namespace util { operator*() { return *_p; } - const pointer + const_pointer operator->() const { return _p; }