summaryrefslogtreecommitdiffstats
path: root/bootloader.cpp
diff options
context:
space:
mode:
authorthat <github@that.at>2015-03-27 00:06:51 +0100
committerthat <github@that.at>2015-03-27 00:06:51 +0100
commit9eadc51fd5994484b69181bd0912b6119b75c313 (patch)
treeef57ecf449b23a37278e78ea226b78613b6ce879 /bootloader.cpp
parent2.8.6.0 (diff)
downloadandroid_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.tar
android_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.tar.gz
android_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.tar.bz2
android_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.tar.lz
android_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.tar.xz
android_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.tar.zst
android_bootable_recovery-9eadc51fd5994484b69181bd0912b6119b75c313.zip
Diffstat (limited to '')
-rw-r--r--bootloader.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/bootloader.cpp b/bootloader.cpp
index 3884c2870..856a7d2b4 100644
--- a/bootloader.cpp
+++ b/bootloader.cpp
@@ -389,6 +389,7 @@ get_args(int *argc, char ***argv) {
if (*argc <= 1) {
FILE *fp = fopen(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
@@ -396,12 +397,17 @@ 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;
+ }
}
fflush(fp);
- if (ferror(fp)) LOGE("Error in %s\n(%s)\n", COMMAND_FILE, strerror(errno));
- fclose(fp);
+ if (ferror(fp)) LOGE("Error in %s\n(%s)\n", COMMAND_FILE, strerror(errno));
+ fclose(fp);
LOGI("Got arguments from %s\n", COMMAND_FILE);
}
}