diff options
Diffstat (limited to '')
-rw-r--r-- | bootloader.cpp | 12 |
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); } } |