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

Commit 22338825 authored by Yifan Hong's avatar Yifan Hong
Browse files

lshal: fix potential out-of-range error.

Test: lshal
Test: lshal --neat
Test: lshal_test

Bug: 35389839
Change-Id: I6c479986b96ec818155b0c5f310f9849d2b4fed8
parent 7971ad7f
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -26,11 +26,9 @@ void TextTable::computeWidth(const std::vector<std::string>& v) {
    if (mWidths.size() < v.size()) {
    if (mWidths.size() < v.size()) {
        mWidths.resize(v.size());
        mWidths.resize(v.size());
    }
    }
    for (size_t i = 0; i < v.size() - 1; ++i) {
    for (size_t i = 0; i < v.size(); ++i) {
        mWidths[i] = std::max(mWidths[i], v[i].length());
        mWidths[i] = std::max(mWidths[i], v[i].length());
    }
    }
    // last column has std::setw(0) to avoid printing unnecessary spaces.
    mWidths[v.size() - 1] = 0;
}
}


void TextTable::dump(std::ostream& out) const {
void TextTable::dump(std::ostream& out) const {
@@ -45,7 +43,8 @@ void TextTable::dump(std::ostream& out) const {
            if (i != 0) {
            if (i != 0) {
                out << " ";
                out << " ";
            }
            }
            if (i < mWidths.size()) {
            // last column does not std::setw to avoid printing unnecessary spaces.
            if (i < row.fields().size() - 1) {
                out << std::setw(mWidths[i]);
                out << std::setw(mWidths[i]);
            }
            }
            out << row.fields()[i];
            out << row.fields()[i];