Merge "updater: Clean up the header lines computation."

This commit is contained in:
Tao Bao 2018-05-21 23:47:51 +00:00 committed by Gerrit Code Review
commit a5735e9b5f

View file

@ -1666,7 +1666,6 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
return StringValue("t"); return StringValue("t");
} }
size_t start = 2;
if (lines.size() < 4) { if (lines.size() < 4) {
ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]", ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]",
lines.size()); lines.size());
@ -1708,8 +1707,6 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
saved_last_command_index = -1; saved_last_command_index = -1;
} }
start += 2;
// Build a map of the available commands // Build a map of the available commands
std::unordered_map<std::string, const Command*> cmd_map; std::unordered_map<std::string, const Command*> cmd_map;
for (size_t i = 0; i < cmdcount; ++i) { for (size_t i = 0; i < cmdcount; ++i) {
@ -1722,17 +1719,18 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
int rc = -1; int rc = -1;
static constexpr size_t kTransferListHeaderLines = 4;
// Subsequent lines are all individual transfer commands // Subsequent lines are all individual transfer commands
for (size_t i = start; i < lines.size(); i++) { for (size_t i = kTransferListHeaderLines; i < lines.size(); i++) {
const std::string& line = lines[i]; const std::string& line = lines[i];
if (line.empty()) continue; if (line.empty()) continue;
params.tokens = android::base::Split(line, " "); params.tokens = android::base::Split(line, " ");
params.cpos = 0; params.cpos = 0;
if (i - start > std::numeric_limits<int>::max()) { if (i - kTransferListHeaderLines > std::numeric_limits<int>::max()) {
params.cmdindex = -1; params.cmdindex = -1;
} else { } else {
params.cmdindex = i - start; params.cmdindex = i - kTransferListHeaderLines;
} }
params.cmdname = params.tokens[params.cpos++].c_str(); params.cmdname = params.tokens[params.cpos++].c_str();
params.cmdline = line.c_str(); params.cmdline = line.c_str();