summaryrefslogtreecommitdiffstats
path: root/edify/expr.cpp
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-05-23 20:15:40 +0200
committerandroid-build-merger <android-build-merger@google.com>2016-05-23 20:15:40 +0200
commit3aabd770d916019d0656bbcd8b102a4033a26a38 (patch)
tree2da9ac489f855912e85dfabefcb92da841b9fe31 /edify/expr.cpp
parentresolve merge conflicts of 86a28d0 to klp-modular-dev am: a5bc59620f am: 36acff7d7e am: 1f814d7630 am: ca45737e27 am: 8a1d4e97ad am: aa02888e55 am: 300af0779d am: fc1d9a49d1 am: b02b2fe392 (diff)
parentMerge "Allow recovery to return error codes" into nyc-dev (diff)
downloadandroid_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.tar
android_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.tar.gz
android_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.tar.bz2
android_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.tar.lz
android_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.tar.xz
android_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.tar.zst
android_bootable_recovery-3aabd770d916019d0656bbcd8b102a4033a26a38.zip
Diffstat (limited to 'edify/expr.cpp')
-rw-r--r--edify/expr.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp
index cd1e08726..cc14fbe93 100644
--- a/edify/expr.cpp
+++ b/edify/expr.cpp
@@ -21,6 +21,11 @@
#include <stdarg.h>
#include <unistd.h>
+#include <string>
+
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+
#include "expr.h"
// Functions should:
@@ -36,7 +41,7 @@ char* Evaluate(State* state, Expr* expr) {
Value* v = expr->fn(expr->name, state, expr->argc, expr->argv);
if (v == NULL) return NULL;
if (v->type != VAL_STRING) {
- ErrorAbort(state, "expecting string, got value type %d", v->type);
+ ErrorAbort(state, kArgsParsingFailure, "expecting string, got value type %d", v->type);
FreeValue(v);
return NULL;
}
@@ -493,15 +498,29 @@ 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 NULL.
+// *state. Returns nullptr.
Value* ErrorAbort(State* state, const char* format, ...) {
- char* buffer = reinterpret_cast<char*>(malloc(4096));
- va_list v;
- va_start(v, format);
- vsnprintf(buffer, 4096, format, v);
- va_end(v);
- free(state->errmsg);
- state->errmsg = buffer;
- return NULL;
+ va_list ap;
+ va_start(ap, format);
+ ErrorAbortV(state, format, ap);
+ va_end(ap);
+ return nullptr;
+}
+
+Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ ErrorAbortV(state, format, ap);
+ va_end(ap);
+ state->cause_code = cause_code;
+ return nullptr;
}