question about vTaskList()

mastupristi wrote on Wednesday, January 25, 2017:

inthe function vTaskList() I found:

/* Write the task name to the string, padding with spaces so it
can be printed in tabular form more easily. */
pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );

/* Write the rest of the string. */
sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );
pcWriteBuffer += strlen( pcWriteBuffer );

I wonder why the task name is written using prvWriteNameToBuffer() and not using the subsequent sprintf with the right formatting.
And why is called strlen instead of using the output of sprintf

If I write:

pcWriteBuffer += sprintf( pcWriteBuffer, "%-*s\t%c\t%u\t%u\t%u\r\n", ( configMAX_TASK_NAME_LEN - 1 ), pxTaskStatusArray[ x ].pcTaskName, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );

It works (I use gcc toolchain).

why do not use this?

best regards
Max

rtel wrote on Wednesday, January 25, 2017:

…because doing that in GCC can, depending on your tools, more than
double the size of your executable image, massively increase the task’s
stack requirements, and unknowingly result in a call to malloc() :slight_smile:

FreeRTOS is often used with very (extremely) stripped down versions of
sprintf() (we provide some ourselves) that only provide functionality
that is actually required, use minimal stack, are thread safe, etc… If
we relied on a full sprintf() implementation then the code would not be
portable to those applications.