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

Commit 3fe61418 authored by Ryan Prichard's avatar Ryan Prichard Committed by Gerrit Code Review
Browse files

Merge changes I2bfa04cc,I156f1032 into main

* changes:
  vr: avoid missing std::char_traits<const T>
  ui: use std::span instead of std::basic_string_view<uint8_t>
parents f86d02b3 20ff570d
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <cctype>
#include <numeric>
#include <optional>
#include <span>

#include <log/log.h>

@@ -81,7 +82,7 @@ uint64_t hash64Len0To16(const char* s, uint64_t len) {
    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 kEdidHeaderLength = 5;
@@ -89,7 +90,8 @@ constexpr size_t kEdidHeaderLength = 5;
constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu;

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 {};
    }

@@ -164,7 +166,7 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) {
        constexpr size_t kDataBlockHeaderSize = 1;
        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.");
            break;
        }
@@ -264,7 +266,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
    }

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

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

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

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

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