Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

configMAX_TASK_NAME_LEN = 1: bug or feature?

Posted by https://www.google.com/accounts on May 31, 2012
Hi,

This macro lets you set the len of the task's name, but if you don't want to use task names in your project (due to limited resources mainly), then you might set it to 1 (in order to include a least the null string terminator). However this approach is not true at all, 'cause if you check the Idle task it already has the name "Idle" and it is fixed!! (five chars). Under this escenario your TCBs are going to crash sooner or later because they aren't allowing space for more than a one character, so critical data in the TCB will be overwritten.

There are two obvious workarounds:

1.- configMAX_TASK_NAME_LEN >5 or
2.- Hack the Idle task creation in order to change "Idle" to ""

None of them convince me so my question is: is it a bug or feature?

Thank you!!

RE: configMAX_TASK_NAME_LEN = 1: bug or feature?

Posted by MEdwards on May 31, 2012
Sorry - but everything in your post is inaccurate.

Look at the copy that copies the task name into the TCP;

#if configMAX_TASK_NAME_LEN > 1
{
/* Don't bring strncpy into the build unnecessarily. */
strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned short ) configMAX_TASK_NAME_LEN );
}
#endif
pxTCB->pcTaskName[ ( unsigned short ) configMAX_TASK_NAME_LEN - ( unsigned short ) 1 ] = ( signed char ) '\0';


configMAX_TASK_NAME_LEN must be at least 1 to fit the NULL, like you say. If it is greater than 1 then only the first configMAX_TASK_NAME_LEN characters are copied in. There is, of course, no buffer overflow, no matter how long the task name is.

RE: configMAX_TASK_NAME_LEN = 1: bug or feature?

Posted by MEdwards on May 31, 2012
"code that copies", not copy that copies. Hopefully the pasted code will display better in this post.

#if configMAX_TASK_NAME_LEN > 1
{
/* Don't bring strncpy into the build unnecessarily. */
strncpy( pxTCB->pcTaskName, pcName, configMAX_TASK_NAME_LEN );
}
#endif
pxTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';

RE: configMAX_TASK_NAME_LEN = 1: bug or feature?

Posted by https://www.google.com/accounts on May 31, 2012
Edward, you're totally right, and I was totally wrong. Cscope shows 10 entries for configMAX_TASK_NAME_LEN, so I didn't know where to start, but now was easier once you pointed it out. Thank you!!


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS