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

Commit b5908aed authored by Yao Chen's avatar Yao Chen
Browse files

Fix incident_helper crash.

The header of top cmd changes from Tasks to Threads, causing the parser to run into
undefined behavior.

Bug: 125377622
Test: adb shell dumpsys incident   && incident_helper_test
Change-Id: I5ae88767dce22f0ee7b49611b2f19889a07e66ac
parent 65c6cd86
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ record_t parseRecordByColumns(const std::string& line, const std::vector<int>& i
    }
    if (lineSize - lastIndex > 0) {
        int beginning = lastIndex;
        if (record.size() == indices.size()) {
        if (record.size() == indices.size() && !record.empty()) {
            // We've already encountered all of the columns...put whatever is
            // left in the last column.
            record.pop_back();
+3 −2
Original line number Diff line number Diff line
@@ -65,8 +65,9 @@ CpuInfoParser::Parse(const int in, const int out) const
        if (line.empty()) continue;

        nline++;

        if (stripPrefix(&line, "Tasks:")) {
        // The format changes from time to time in toybox/toys/posix/ps.c
        // With -H, it prints Threads instead of Tasks (FLAG(H)?"Thread":"Task")
        if (stripPrefix(&line, "Threads:")) {
            writeSuffixLine(&proto, CpuInfoProto::TASK_STATS, line, COMMA_DELIMITER,
                CpuInfoProto::TaskStats::_FIELD_COUNT,
                CpuInfoProto::TaskStats::_FIELD_NAMES,
+4 −4
Original line number Diff line number Diff line
Tasks: 2038 total,   1 running,2033 sleeping,   0 stopped,   0 zombie
Threads: 2038 total,   1 running,2033 sleeping,   0 stopped,   0 zombie

  Mem:   3842668k total,  3761936k used,    80732k free,   220188k buffers