summaryrefslogtreecommitdiffstats
path: root/recovery.cpp
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2013-06-04 21:17:42 +0200
committerAndroid Git Automerger <android-git-automerger@android.com>2013-06-04 21:17:42 +0200
commit7839f64bafff349bff630df29cae11dfee05a1e5 (patch)
treef41574ab66b5eec556e0ff8b69b2a0a93fdc14a2 /recovery.cpp
parentam da1ebaef: recovery: save logs from the last few invocations of recovery (diff)
parentam d51bfc9b: Merge "Fix the potential segmentation fault" (diff)
downloadandroid_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.tar
android_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.tar.gz
android_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.tar.bz2
android_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.tar.lz
android_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.tar.xz
android_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.tar.zst
android_bootable_recovery-7839f64bafff349bff630df29cae11dfee05a1e5.zip
Diffstat (limited to '')
-rw-r--r--recovery.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 840e63c42..c82844d25 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -200,6 +200,7 @@ get_args(int *argc, char ***argv) {
if (*argc <= 1) {
FILE *fp = fopen_path(COMMAND_FILE, "r");
if (fp != NULL) {
+ char *token;
char *argv0 = (*argv)[0];
*argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
(*argv)[0] = argv0; // use the same program name
@@ -207,7 +208,12 @@ get_args(int *argc, char ***argv) {
char buf[MAX_ARG_LENGTH];
for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
if (!fgets(buf, sizeof(buf), fp)) break;
- (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline.
+ token = strtok(buf, "\r\n");
+ if (token != NULL) {
+ (*argv)[*argc] = strdup(token); // Strip newline.
+ } else {
+ --*argc;
+ }
}
check_and_fclose(fp, COMMAND_FILE);