summaryrefslogtreecommitdiff
path: root/FreeRTOS/Source
diff options
context:
space:
mode:
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2013-06-25 14:03:02 +0000
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2013-06-25 14:03:02 +0000
commitd252fd97233f8f7792d776a7b95628726c8c80c1 (patch)
tree5473bbda6c56a88e6bd32c33e4d0b2c6cb664fae /FreeRTOS/Source
parent2e0a51760b6945878fec32ba50ec076d55afc0c8 (diff)
downloadfreertos-d252fd97233f8f7792d776a7b95628726c8c80c1.tar.gz
Remove reliance on strncpy() function.
git-svn-id: http://svn.code.sf.net/p/freertos/code/trunk@1950 1d2547de-c912-0410-9cb9-b8ca96c0e9e2
Diffstat (limited to 'FreeRTOS/Source')
-rw-r--r--FreeRTOS/Source/tasks.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c
index 6232e7eb4..bc0a6e01a 100644
--- a/FreeRTOS/Source/tasks.c
+++ b/FreeRTOS/Source/tasks.c
@@ -2249,14 +2249,25 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const pcName, unsigned portBASE_TYPE uxPriority, const xMemoryRegion * const xRegions, unsigned short usStackDepth )
{
- /* Store the function name in the TCB. */
- #if configMAX_TASK_NAME_LEN > 1
+portBASE_TYPE x;
+
+ /* Store the task name in the TCB. */
+ for( x = 0; x < configMAX_TASK_NAME_LEN; x++ )
{
- /* Don't bring strncpy into the build unnecessarily. */
- strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned short ) configMAX_TASK_NAME_LEN );
+ pxTCB->pcTaskName[ x ] = pcName[ x ];
+
+ /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than
+ configMAX_TASK_NAME_LEN characters just in case the memory after the
+ string is not accessible (extremely unlikely). */
+ if( pcName[ x ] == 0x00 )
+ {
+ break;
+ }
}
- #endif /* configMAX_TASK_NAME_LEN */
- pxTCB->pcTaskName[ ( unsigned short ) configMAX_TASK_NAME_LEN - ( unsigned short ) 1 ] = ( signed char ) '\0';
+
+ /* Ensure the name string is terminated in the case that the string length
+ was greater or equal to configMAX_TASK_NAME_LEN. */
+ pxTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = ( signed char ) '\0';
/* This is used as an array index so must ensure it's not too large. First
remove the privilege bit if one is present. */