diff options
author | Tao Bao <tbao@google.com> | 2016-10-05 08:13:22 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-10-05 08:13:22 +0200 |
commit | 6674f22a2f979ad71933d353f37743c4987c8d00 (patch) | |
tree | 64a8c1e78aa282460aebf39d3f4147d00ffa0fcc /edify/expr.cpp | |
parent | Merge "recovery: drop log/logger.h" (diff) | |
parent | Merge "edify: Move State.script and State.errmsg to std::string." (diff) | |
download | android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.tar android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.tar.gz android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.tar.bz2 android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.tar.lz android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.tar.xz android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.tar.zst android_bootable_recovery-6674f22a2f979ad71933d353f37743c4987c8d00.zip |
Diffstat (limited to 'edify/expr.cpp')
-rw-r--r-- | edify/expr.cpp | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp index ecb1bea1a..aa3a55a87 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp @@ -107,8 +107,7 @@ Value* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) { Value* IfElseFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2 && argc != 3) { - free(state->errmsg); - state->errmsg = strdup("ifelse expects 2 or 3 arguments"); + state->errmsg = "ifelse expects 2 or 3 arguments"; return NULL; } char* cond = Evaluate(state, argv[0]); @@ -134,11 +133,10 @@ Value* AbortFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc > 0) { msg = Evaluate(state, argv[0]); } - free(state->errmsg); if (msg) { state->errmsg = msg; } else { - state->errmsg = strdup("called abort()"); + state->errmsg = "called abort()"; } return NULL; } @@ -153,15 +151,8 @@ Value* AssertFn(const char* name, State* state, int argc, Expr* argv[]) { int b = BooleanString(v); free(v); if (!b) { - int prefix_len; int len = argv[i]->end - argv[i]->start; - char* err_src = reinterpret_cast<char*>(malloc(len + 20)); - strcpy(err_src, "assert failed: "); - prefix_len = strlen(err_src); - memcpy(err_src + prefix_len, state->script + argv[i]->start, len); - err_src[prefix_len + len] = '\0'; - free(state->errmsg); - state->errmsg = err_src; + state->errmsg = "assert failed: " + state->script.substr(argv[i]->start, len); return NULL; } } @@ -279,8 +270,7 @@ Value* SequenceFn(const char* name, State* state, int argc, Expr* argv[]) { Value* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - free(state->errmsg); - state->errmsg = strdup("less_than_int expects 2 arguments"); + state->errmsg = "less_than_int expects 2 arguments"; return NULL; } @@ -314,8 +304,7 @@ Value* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) { Value* GreaterThanIntFn(const char* name, State* state, int argc, Expr* argv[]) { if (argc != 2) { - free(state->errmsg); - state->errmsg = strdup("greater_than_int expects 2 arguments"); + state->errmsg = "greater_than_int expects 2 arguments"; return NULL; } @@ -499,20 +488,12 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) { return args; } -static void ErrorAbortV(State* state, const char* format, va_list ap) { - std::string buffer; - android::base::StringAppendV(&buffer, format, ap); - free(state->errmsg); - state->errmsg = strdup(buffer.c_str()); - return; -} - // Use printf-style arguments to compose an error message to put into // *state. Returns nullptr. Value* ErrorAbort(State* state, const char* format, ...) { va_list ap; va_start(ap, format); - ErrorAbortV(state, format, ap); + android::base::StringAppendV(&state->errmsg, format, ap); va_end(ap); return nullptr; } @@ -520,8 +501,14 @@ Value* ErrorAbort(State* state, const char* format, ...) { Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) { va_list ap; va_start(ap, format); - ErrorAbortV(state, format, ap); + android::base::StringAppendV(&state->errmsg, format, ap); va_end(ap); state->cause_code = cause_code; return nullptr; } + +State::State(const std::string& script, void* cookie) : + script(script), + cookie(cookie) { +} + |