applypatch: use vector to store data in FileContents.

Bug: 26906416
Change-Id: Ib53b445cd415a1ed5e95733fbc4073f9ef4dbc43
This commit is contained in:
Yabin Cui
2016-02-11 18:10:31 -08:00
parent 7043206503
commit d6c93afcc2
4 changed files with 77 additions and 126 deletions
+11 -10
View File
@@ -1398,21 +1398,22 @@ Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) {
char* filename;
if (ReadArgs(state, argv, 1, &filename) < 0) return NULL;
Value* v = reinterpret_cast<Value*>(malloc(sizeof(Value)));
Value* v = static_cast<Value*>(malloc(sizeof(Value)));
if (v == nullptr) {
return nullptr;
}
v->type = VAL_BLOB;
v->size = -1;
v->data = nullptr;
FileContents fc;
if (LoadFileContents(filename, &fc) != 0) {
free(filename);
v->size = -1;
v->data = NULL;
free(fc.data);
return v;
v->data = static_cast<char*>(malloc(fc.data.size()));
if (v->data != nullptr) {
memcpy(v->data, fc.data.data(), fc.data.size());
v->size = fc.data.size();
}
}
v->size = fc.size;
v->data = (char*)fc.data;
free(filename);
return v;
}