[Cbe-oss-dev] [PATCH] libspe: elfspe: set argv[argc] = NULL

D. Herrendoerfer d.herrendoerfer at herrendoerfer.name
Wed May 23 11:49:03 EST 2007


Yes, ok with me.

D.Herrendoerfer

On Wed, 2007-05-23 at 17:21 +0900, Masato Noguchi wrote:
> Programming language-C standard says "argv[argc] shall be a null pointer."
> but, a value of argv[argc] passed from elfspe to spe program is undefined in current implementation.
> This patch fix it.
> 
> is it ok to apply?
> 
> --
> 
>  libspe/elfspe.c         |    5 +++--
>  libspe2/elfspe/elfspe.c |    5 +++--
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> --
> Index: libspe/libspe2/elfspe/elfspe.c
> ===================================================================
> --- libspe/libspe2/elfspe/elfspe.c	(revision 41)
> +++ libspe/libspe2/elfspe/elfspe.c	(working copy)
> @@ -99,7 +99,7 @@
>      for (i = 0; i < argc; i++) {
>  	nbytes += strlen(argv[i]) + 1;
>      }
> -    nbytes += (argc * sizeof(unsigned int));
> +    nbytes += ((argc + 1) * sizeof(unsigned int));
>      nbytes = (nbytes + 15) & ~(15);
>      if (nbytes > spe_arg_max) {
>  	return 2;
> @@ -113,7 +113,7 @@
>      ptr = (char *)start;
>      end = (char *)start + nbytes;
>      argv_offsets = (unsigned int *) ptr;
> -    ptr += (argc * sizeof(unsigned int));
> +    ptr += ((argc + 1) * sizeof(unsigned int));
>      for (i = 0; i < argc; i++) {
>  	int len = strlen(argv[i]) + 1;
>  	argv_offsets[i] = LS_SIZE - ((unsigned int) (end - ptr));
> @@ -121,6 +121,7 @@
>  	memcpy(ptr, argv[i], len);
>  	ptr += len;
>      }
> +    argv_offsets[argc] = NULL;
>      ret->r3[0] = argc;
>      ret->r4[0] = LS_SIZE - nbytes;
>      ret->r4[1] = addr64.ui[0];
> Index: libspe/libspe/elfspe.c
> ===================================================================
> --- libspe/libspe/elfspe.c	(revision 41)
> +++ libspe/libspe/elfspe.c	(working copy)
> @@ -100,7 +100,7 @@
>      for (i = 0; i < argc; i++) {
>  	nbytes += strlen(argv[i]) + 1;
>      }
> -    nbytes += (argc * sizeof(unsigned int));
> +    nbytes += ((argc + 1) * sizeof(unsigned int));
>      nbytes = (nbytes + 15) & ~(15);
>      if (nbytes > spe_arg_max) {
>  	return 2;
> @@ -114,7 +114,7 @@
>      ptr = (char *)start;
>      end = (char *)start + nbytes;
>      argv_offsets = (unsigned int *) ptr;
> -    ptr += (argc * sizeof(unsigned int));
> +    ptr += ((argc + 1) * sizeof(unsigned int));
>      for (i = 0; i < argc; i++) {
>  	int len = strlen(argv[i]) + 1;
>  	argv_offsets[i] = LS_SIZE - ((unsigned int) (end - ptr));
> @@ -122,6 +122,7 @@
>  	memcpy(ptr, argv[i], len);
>  	ptr += len;
>      }
> +    argv_offsets[argc] = NULL;
>      ret->r3[0] = argc;
>      ret->r4[0] = LS_SIZE - nbytes;
>      ret->r4[1] = addr64.ui[0];
> 
> _______________________________________________
> cbe-oss-dev mailing list
> cbe-oss-dev at ozlabs.org
> https://ozlabs.org/mailman/listinfo/cbe-oss-dev




More information about the cbe-oss-dev mailing list