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

Masato Noguchi Masato.Noguchi at jp.sony.com
Wed May 23 18:21:58 EST 2007


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];




More information about the cbe-oss-dev mailing list