Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88a7173f authored by Ryan Prichard's avatar Ryan Prichard Committed by Automerger Merge Worker
Browse files

Merge changes I2bfa04cc,I156f1032 into main am: 3fe61418 am: 425caa85

parents 7b203676 425caa85
Loading
Loading
Loading
Loading
+11 −9
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <cctype>
#include <cctype>
#include <numeric>
#include <numeric>
#include <optional>
#include <optional>
#include <span>


#include <log/log.h>
#include <log/log.h>


@@ -81,7 +82,7 @@ uint64_t hash64Len0To16(const char* s, uint64_t len) {
    return k2;
    return k2;
}
}


using byte_view = std::basic_string_view<uint8_t>;
using byte_view = std::span<const uint8_t>;


constexpr size_t kEdidBlockSize = 128;
constexpr size_t kEdidBlockSize = 128;
constexpr size_t kEdidHeaderLength = 5;
constexpr size_t kEdidHeaderLength = 5;
@@ -89,7 +90,8 @@ constexpr size_t kEdidHeaderLength = 5;
constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu;
constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu;


std::optional<uint8_t> getEdidDescriptorType(const byte_view& view) {
std::optional<uint8_t> getEdidDescriptorType(const byte_view& view) {
    if (view.size() < kEdidHeaderLength || view[0] || view[1] || view[2] || view[4]) {
    if (static_cast<size_t>(view.size()) < kEdidHeaderLength || view[0] || view[1] || view[2] ||
        view[4]) {
        return {};
        return {};
    }
    }


@@ -164,7 +166,7 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) {
        constexpr size_t kDataBlockHeaderSize = 1;
        constexpr size_t kDataBlockHeaderSize = 1;
        const size_t dataBlockSize = bodyLength + kDataBlockHeaderSize;
        const size_t dataBlockSize = bodyLength + kDataBlockHeaderSize;


        if (block.size() < dataBlockOffset + dataBlockSize) {
        if (static_cast<size_t>(block.size()) < dataBlockOffset + dataBlockSize) {
            ALOGW("Invalid EDID: CEA 861 data block is truncated.");
            ALOGW("Invalid EDID: CEA 861 data block is truncated.");
            break;
            break;
        }
        }
@@ -264,7 +266,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
    }
    }


    byte_view view(edid.data(), edid.size());
    byte_view view(edid.data(), edid.size());
    view.remove_prefix(kDescriptorOffset);
    view = view.subspan(kDescriptorOffset);


    std::string_view displayName;
    std::string_view displayName;
    std::string_view serialNumber;
    std::string_view serialNumber;
@@ -274,13 +276,13 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
    constexpr size_t kDescriptorLength = 18;
    constexpr size_t kDescriptorLength = 18;


    for (size_t i = 0; i < kDescriptorCount; i++) {
    for (size_t i = 0; i < kDescriptorCount; i++) {
        if (view.size() < kDescriptorLength) {
        if (static_cast<size_t>(view.size()) < kDescriptorLength) {
            break;
            break;
        }
        }


        if (const auto type = getEdidDescriptorType(view)) {
        if (const auto type = getEdidDescriptorType(view)) {
            byte_view descriptor(view.data(), kDescriptorLength);
            byte_view descriptor(view.data(), kDescriptorLength);
            descriptor.remove_prefix(kEdidHeaderLength);
            descriptor = descriptor.subspan(kEdidHeaderLength);


            switch (*type) {
            switch (*type) {
                case 0xfc:
                case 0xfc:
@@ -295,7 +297,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
            }
            }
        }
        }


        view.remove_prefix(kDescriptorLength);
        view = view.subspan(kDescriptorLength);
    }
    }


    std::string_view modelString = displayName;
    std::string_view modelString = displayName;
@@ -327,8 +329,8 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
        const size_t numExtensions = edid[kNumExtensionsOffset];
        const size_t numExtensions = edid[kNumExtensionsOffset];
        view = byte_view(edid.data(), edid.size());
        view = byte_view(edid.data(), edid.size());
        for (size_t blockNumber = 1; blockNumber <= numExtensions; blockNumber++) {
        for (size_t blockNumber = 1; blockNumber <= numExtensions; blockNumber++) {
            view.remove_prefix(kEdidBlockSize);
            view = view.subspan(kEdidBlockSize);
            if (view.size() < kEdidBlockSize) {
            if (static_cast<size_t>(view.size()) < kEdidBlockSize) {
                ALOGW("Invalid EDID: block %zu is truncated.", blockNumber);
                ALOGW("Invalid EDID: block %zu is truncated.", blockNumber);
                break;
                break;
            }
            }
+2 −2
Original line number Original line Diff line number Diff line
@@ -17,12 +17,12 @@ namespace rpc {
// C strings more efficient by avoiding unnecessary copies when remote method
// C strings more efficient by avoiding unnecessary copies when remote method
// signatures specify std::basic_string arguments or return values.
// signatures specify std::basic_string arguments or return values.
template <typename CharT = std::string::value_type,
template <typename CharT = std::string::value_type,
          typename Traits = std::char_traits<CharT>>
          typename Traits = std::char_traits<std::remove_cv_t<CharT>>>
class StringWrapper {
class StringWrapper {
 public:
 public:
  // Define types in the style of STL strings to support STL operators.
  // Define types in the style of STL strings to support STL operators.
  typedef Traits traits_type;
  typedef Traits traits_type;
  typedef typename Traits::char_type value_type;
  typedef CharT value_type;
  typedef std::size_t size_type;
  typedef std::size_t size_type;
  typedef value_type& reference;
  typedef value_type& reference;
  typedef const value_type& const_reference;
  typedef const value_type& const_reference;