[PATCH 02/20] libbsp/shared/bspinit.c: Document assumption of NULL returned
Gedare Bloom
gedare at rtems.org
Wed Nov 26 15:08:44 UTC 2014
On Tue, Nov 25, 2014 at 6:02 PM, Joel Sherrill
<joel.sherrill at oarcorp.com> wrote:
> From: Josh Oguin <josh.oguin at oarcorp.com>
>
> ---
> c/src/lib/libbsp/shared/bspinit.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/c/src/lib/libbsp/shared/bspinit.c b/c/src/lib/libbsp/shared/bspinit.c
> index 86c950c..b524389 100644
> --- a/c/src/lib/libbsp/shared/bspinit.c
> +++ b/c/src/lib/libbsp/shared/bspinit.c
> @@ -37,12 +37,10 @@ rtems_task Init (rtems_task_argument arg)
> char** argv = NULL;
> int result = -124;
>
> - if (boot_cmdline)
> - {
> + if (boot_cmdline) {
> cmdline = malloc (strlen (boot_cmdline) + 1);
>
> - if (cmdline)
> - {
> + if (cmdline) {
> strcpy (cmdline, boot_cmdline);
>
> command = cmdline;
> @@ -50,8 +48,7 @@ rtems_task Init (rtems_task_argument arg)
> /*
> * Break the line up into arguments with "" being ignored.
> */
> - while (true)
> - {
> + while (true) {
> command = strtok (command, " \t\r\n");
> if (command == NULL)
> break;
> @@ -59,22 +56,25 @@ rtems_task Init (rtems_task_argument arg)
> 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*));
>
Cleaner to change it to
argv = argc > 0 ? calloc(argc,sizeof(char*)) : NULL;
> - if (argv)
> - {
> + if (argv) {
> int a;
>
> command = cmdline;
> argv[0] = command;
>
> - for (a = 1; a < argc; a++)
> - {
> + for (a = 1; a < argc; a++) {
> command += strlen (command) + 1;
> argv[a] = command;
> }
> - }
> - else
> + } else
> argc = 0;
> }
> }
> --
> 1.9.3
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
More information about the devel
mailing list