Remove malloc in edify functions

And switch them to std::vector & std::unique_ptr

Bug: 32117870
Test: recovery tests passed on sailfish
Change-Id: I5a45951c4bdf895be311d6d760e52e7a1b0798c3
This commit is contained in:
Tianjie Xu
2017-03-22 14:20:57 -07:00
parent d882b8892a
commit c444732540
9 changed files with 331 additions and 257 deletions
+5 -4
View File
@@ -27,18 +27,19 @@
#include <errno.h>
#include <stdio.h>
#include <memory>
#include <string>
#include <android-base/file.h>
#include "expr.h"
static void ExprDump(int depth, const Expr* n, const std::string& script) {
static void ExprDump(int depth, const std::unique_ptr<Expr>& n, const std::string& script) {
printf("%*s", depth*2, "");
printf("%s %p (%d-%d) \"%s\"\n",
n->name == NULL ? "(NULL)" : n->name, n->fn, n->start, n->end,
n->name.c_str(), n->fn, n->start, n->end,
script.substr(n->start, n->end - n->start).c_str());
for (int i = 0; i < n->argc; ++i) {
for (size_t i = 0; i < n->argv.size(); ++i) {
ExprDump(depth+1, n->argv[i], script);
}
}
@@ -57,7 +58,7 @@ int main(int argc, char** argv) {
return 1;
}
Expr* root;
std::unique_ptr<Expr> root;
int error_count = 0;
int error = parse_string(buffer.data(), &root, &error_count);
printf("parse returned %d; %d errors encountered\n", error, error_count);