libbsp/shared/bspinit.c: Document assumption of NULL returned

This commit is contained in:
Josh Oguin
2014-11-19 14:26:11 -06:00
committed by Joel Sherrill
parent ba3b6fdc89
commit 61f8d668d0

View File

@@ -37,12 +37,10 @@ rtems_task Init (rtems_task_argument arg)
char** argv = NULL; char** argv = NULL;
int result = -124; int result = -124;
if (boot_cmdline) if (boot_cmdline) {
{
cmdline = malloc (strlen (boot_cmdline) + 1); cmdline = malloc (strlen (boot_cmdline) + 1);
if (cmdline) if (cmdline) {
{
strcpy (cmdline, boot_cmdline); strcpy (cmdline, boot_cmdline);
command = cmdline; command = cmdline;
@@ -50,8 +48,7 @@ rtems_task Init (rtems_task_argument arg)
/* /*
* Break the line up into arguments with "" being ignored. * Break the line up into arguments with "" being ignored.
*/ */
while (true) while (true) {
{
command = strtok (command, " \t\r\n"); command = strtok (command, " \t\r\n");
if (command == NULL) if (command == NULL)
break; break;
@@ -59,22 +56,25 @@ rtems_task Init (rtems_task_argument arg)
command = '\0'; command = '\0';
} }
/*
* If there are arguments, allocate enough memory for the argv
* array to be passed into main().
*
* NOTE: If argc is 0, then argv will be NULL.
*/
argv = calloc (argc, sizeof (char*)); argv = calloc (argc, sizeof (char*));
if (argv) if (argv) {
{
int a; int a;
command = cmdline; command = cmdline;
argv[0] = command; argv[0] = command;
for (a = 1; a < argc; a++) for (a = 1; a < argc; a++) {
{
command += strlen (command) + 1; command += strlen (command) + 1;
argv[a] = command; argv[a] = command;
} }
} } else
else
argc = 0; argc = 0;
} }
} }