From aced5d9e4e438ba478ce54f9217166b8ab7cc24f Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 12 Oct 2016 10:55:04 -0700 Subject: Change StringValue to use std::string Changing the field of 'Value' in edify to std::string from char*. Meanwhile cleaning up the users of 'Value' and switching them to cpp style. Test: compontent tests passed. Bug: 31713288 Change-Id: Iec5a7d601b1e4ca40935bf1c70d325dafecec235 --- applypatch/main.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'applypatch/main.cpp') diff --git a/applypatch/main.cpp b/applypatch/main.cpp index 1968ae48f..a3a45d06f 100644 --- a/applypatch/main.cpp +++ b/applypatch/main.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include "applypatch/applypatch.h" @@ -30,7 +31,12 @@ static int CheckMode(int argc, char** argv) { if (argc < 3) { return 2; } - return applypatch_check(argv[2], argc-3, argv+3); + std::vector sha1; + for (int i = 3; i < argc; i++) { + sha1.push_back(argv[i]); + } + + return applypatch_check(argv[2], sha1); } static int SpaceMode(int argc, char** argv) { @@ -49,11 +55,13 @@ static int SpaceMode(int argc, char** argv) { // Parse arguments (which should be of the form ":" // into the new parallel arrays *sha1s and *files.Returns true on // success. -static bool ParsePatchArgs(int argc, char** argv, std::vector* sha1s, +static bool ParsePatchArgs(int argc, char** argv, std::vector* sha1s, std::vector* files) { - uint8_t digest[SHA_DIGEST_LENGTH]; - + if (sha1s == nullptr) { + return false; + } for (int i = 0; i < argc; ++i) { + uint8_t digest[SHA_DIGEST_LENGTH]; char* colon = strchr(argv[i], ':'); if (colon == nullptr) { printf("no ':' in patch argument \"%s\"\n", argv[i]); @@ -83,18 +91,15 @@ static int FlashMode(const char* src_filename, const char* tgt_filename, static int PatchMode(int argc, char** argv) { FileContents bonusFc; - Value bonusValue; - Value* bonus = nullptr; + Value bonus(VAL_INVALID, ""); if (argc >= 3 && strcmp(argv[1], "-b") == 0) { if (LoadFileContents(argv[2], &bonusFc) != 0) { printf("failed to load bonus file %s\n", argv[2]); return 1; } - bonus = &bonusValue; - bonus->type = VAL_BLOB; - bonus->size = bonusFc.data.size(); - bonus->data = reinterpret_cast(bonusFc.data.data()); + bonus.type = VAL_BLOB; + bonus.data = reinterpret_cast(bonusFc.data.data()); argc -= 2; argv += 2; } @@ -112,29 +117,26 @@ static int PatchMode(int argc, char** argv) { // If no : is provided, it is in flash mode. if (argc == 5) { - if (bonus != nullptr) { + if (bonus.type != VAL_INVALID) { printf("bonus file not supported in flash mode\n"); return 1; } return FlashMode(argv[1], argv[2], argv[3], target_size); } - std::vector sha1s; + std::vector sha1s; std::vector files; if (!ParsePatchArgs(argc-5, argv+5, &sha1s, &files)) { printf("failed to parse patch args\n"); return 1; } - std::vector patches(files.size()); - std::vector patch_ptrs(files.size()); + std::vector patches; + std::vector patch_ptrs; for (size_t i = 0; i < files.size(); ++i) { - patches[i].type = VAL_BLOB; - patches[i].size = files[i].data.size(); - patches[i].data = reinterpret_cast(files[i].data.data()); - patch_ptrs[i] = &patches[i]; + patches.push_back(Value(VAL_BLOB, reinterpret_cast(files[i].data.data()))); + patch_ptrs.push_back(&patches[i]); } return applypatch(argv[1], argv[2], argv[3], target_size, - patch_ptrs.size(), sha1s.data(), - patch_ptrs.data(), bonus); + sha1s, patch_ptrs.data(), &bonus); } // This program applies binary patches to files in a way that is safe -- cgit v1.2.3