[Cbe-oss-dev] [PATCH 8/9]MARS: Task get name return null

Yuji Mano yuji.mano at am.sony.com
Sat Oct 18 10:29:09 EST 2008


This fixes mars_task_get_name function so that if user specified NULL during
task creation, NULL will be returned rather than a pointer to an uninitialized
string array.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

---
 src/host/lib/task.c |    4 +++-
 src/mpu/lib/task.c  |    4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

--- a/src/host/lib/task.c
+++ b/src/host/lib/task.c
@@ -98,8 +98,10 @@ int mars_task_create(struct mars_context
 	/* initialize task id */
 	task->id.mars_context_ea = mars_ptr_to_ea(mars);
 	task->id.workload_id = workload_id;
-	if (name)
+	if (name && strlen(name))
 		strcpy((char *)task->id.name, name);
+	else
+		task->id.name[0] = 0;
 
 	/* initialize the elf parameters */
 	task->exec_ea = mars_ptr_to_ea((void *)ehdr + phdr->p_offset);
--- a/src/mpu/lib/task.c
+++ b/src/mpu/lib/task.c
@@ -35,6 +35,8 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
+#include <stdlib.h>
+
 #include "mars/task.h"
 #include "mars/task_types.h"
 #include "mars/error.h"
@@ -160,5 +162,5 @@ const char *mars_task_get_name(void)
 
 	task = (struct mars_task_context *)mars_get_workload();
 
-	return (const char *)task->id.name;
+	return task->id.name[0] ? (const char *)task->id.name : NULL;
 }





More information about the cbe-oss-dev mailing list