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

Commit 6742ee98 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Correctly handle empty vector when printing

before this CL, an empty vector passed to 'dumpVector' would cause a
crash (in the good case) and undefined behaviour otherwise.

In this CL, fix this function.

Bug: 211379801
Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: I93f4defb947f41d68f0ec22bd35b6c069fbc15e4
parent b507b71c
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -117,11 +117,12 @@ std::string dumpMapKeys(const std::map<K, V>& map,
template <typename T>
std::string dumpVector(const std::vector<T>& values,
                       std::string (*valueToString)(const T&) = constToString) {
    std::string dump = valueToString(values[0]);
    for (size_t i = 1; i < values.size(); i++) {
        dump += ", " + valueToString(values[i]);
    std::string out;
    for (const auto& value : values) {
        out += out.empty() ? "[" : ", ";
        out += valueToString(value);
    }
    return dump;
    return out.empty() ? "[]" : (out + "]");
}

const char* toString(bool value);