2121#include < cctype>
2222#include < numeric>
2323#include < optional>
24+ #include < span>
2425
2526#include < log/log.h>
2627
@@ -81,15 +82,16 @@ uint64_t hash64Len0To16(const char* s, uint64_t len) {
8182 return k2;
8283}
8384
84- using byte_view = std::basic_string_view< uint8_t >;
85+ using byte_view = std::span< const uint8_t >;
8586
8687constexpr size_t kEdidBlockSize = 128 ;
8788constexpr size_t kEdidHeaderLength = 5 ;
8889
8990constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu ;
9091
9192std::optional<uint8_t > getEdidDescriptorType (const byte_view& view) {
92- if (view.size () < kEdidHeaderLength || view[0 ] || view[1 ] || view[2 ] || view[4 ]) {
93+ if (static_cast <size_t >(view.size ()) < kEdidHeaderLength || view[0 ] || view[1 ] || view[2 ] ||
94+ view[4 ]) {
9395 return {};
9496 }
9597
@@ -164,7 +166,7 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) {
164166 constexpr size_t kDataBlockHeaderSize = 1 ;
165167 const size_t dataBlockSize = bodyLength + kDataBlockHeaderSize ;
166168
167- if (block.size () < dataBlockOffset + dataBlockSize) {
169+ if (static_cast < size_t >( block.size () ) < dataBlockOffset + dataBlockSize) {
168170 ALOGW (" Invalid EDID: CEA 861 data block is truncated." );
169171 break ;
170172 }
@@ -264,7 +266,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
264266 }
265267
266268 byte_view view (edid.data (), edid.size ());
267- view. remove_prefix (kDescriptorOffset );
269+ view = view. subspan (kDescriptorOffset );
268270
269271 std::string_view displayName;
270272 std::string_view serialNumber;
@@ -274,13 +276,13 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
274276 constexpr size_t kDescriptorLength = 18 ;
275277
276278 for (size_t i = 0 ; i < kDescriptorCount ; i++) {
277- if (view.size () < kDescriptorLength ) {
279+ if (static_cast < size_t >( view.size () ) < kDescriptorLength ) {
278280 break ;
279281 }
280282
281283 if (const auto type = getEdidDescriptorType (view)) {
282284 byte_view descriptor (view.data (), kDescriptorLength );
283- descriptor. remove_prefix (kEdidHeaderLength );
285+ descriptor = descriptor. subspan (kEdidHeaderLength );
284286
285287 switch (*type) {
286288 case 0xfc :
@@ -295,7 +297,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
295297 }
296298 }
297299
298- view. remove_prefix (kDescriptorLength );
300+ view = view. subspan (kDescriptorLength );
299301 }
300302
301303 std::string_view modelString = displayName;
@@ -327,8 +329,8 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) {
327329 const size_t numExtensions = edid[kNumExtensionsOffset ];
328330 view = byte_view (edid.data (), edid.size ());
329331 for (size_t blockNumber = 1 ; blockNumber <= numExtensions; blockNumber++) {
330- view. remove_prefix (kEdidBlockSize );
331- if (view.size () < kEdidBlockSize ) {
332+ view = view. subspan (kEdidBlockSize );
333+ if (static_cast < size_t >( view.size () ) < kEdidBlockSize ) {
332334 ALOGW (" Invalid EDID: block %zu is truncated." , blockNumber);
333335 break ;
334336 }
0 commit comments