From 51b958d57c41c019bea1114fccb914d57f291ab6 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Fri, 21 May 2021 09:05:39 -0700 Subject: [PATCH] Fix implicit cast from ssize_t to size_t in KeyedVector.h Fixes a compiler warning for implicit conversion changes from signed to unsigned which surfaced when refactoring native input libraries. Add an explicit cast to avoid adding -Wno-sign-conversion compile flags. Test: b libsurfaceflinger_unittest Bug: b/188792659 Change-Id: I1b9309c3530d6063d5cefcaa31af84d9cebc3f5d Merged-In: I8866aef7f09ca5173604abe18c586b68bbf12ed6 --- libutils/include/utils/KeyedVector.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libutils/include/utils/KeyedVector.h b/libutils/include/utils/KeyedVector.h index 7bda99beb..5cf7a1165 100644 --- a/libutils/include/utils/KeyedVector.h +++ b/libutils/include/utils/KeyedVector.h @@ -47,7 +47,7 @@ public: inline void clear() { mVector.clear(); } - /*! + /*! * vector stats */ @@ -63,14 +63,14 @@ public: // returns true if the arguments is known to be identical to this vector inline bool isIdenticalTo(const KeyedVector& rhs) const; - /*! + /*! * accessors */ - const VALUE& valueFor(const KEY& key) const; - const VALUE& valueAt(size_t index) const; - const KEY& keyAt(size_t index) const; - ssize_t indexOfKey(const KEY& key) const; - const VALUE& operator[] (size_t index) const; + const VALUE& valueFor(const KEY& key) const; + const VALUE& valueAt(size_t index) const; + const KEY& keyAt(size_t index) const; + ssize_t indexOfKey(const KEY& key) const; + const VALUE& operator[](size_t index) const; /*! * modifying the array @@ -79,10 +79,10 @@ public: VALUE& editValueFor(const KEY& key); VALUE& editValueAt(size_t index); - /*! + /*! * add/insert/replace items */ - + ssize_t add(const KEY& key, const VALUE& item); ssize_t replaceValueFor(const KEY& key, const VALUE& item); ssize_t replaceValueAt(size_t index, const VALUE& item); @@ -93,7 +93,7 @@ public: ssize_t removeItem(const KEY& key); ssize_t removeItemsAt(size_t index, size_t count = 1); - + private: SortedVector< key_value_pair_t > mVector; }; @@ -208,7 +208,7 @@ DefaultKeyedVector::DefaultKeyedVector(const VALUE& defValue) template inline const VALUE& DefaultKeyedVector::valueFor(const KEY& key) const { ssize_t i = this->indexOfKey(key); - return i >= 0 ? KeyedVector::valueAt(i) : mDefault; + return i >= 0 ? KeyedVector::valueAt(static_cast(i)) : mDefault; } } // namespace android