Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sprintf with snprintf #802

Merged
merged 16 commits into from
Sep 26, 2023
Merged

Conversation

aggarg
Copy link
Member

@aggarg aggarg commented Sep 21, 2023

Description

This change necessitates the introduction of 2 new APIs:

void vTaskListTasks( char * pcWriteBuffer, size_t uxBufferLength );
void vTaskGetRunTimeStatistics( char * pcWriteBuffer, size_t uxBufferLength );

These 2 APIs behave exactly as vTaskList and vTaskGetRunTimeStats except the fact that they take the length of the pcWriteBuffer as the second argument to ensure that we do not write past the buffer.

vTaskList and vTaskGetRunTimeStats assume that the length of the buffer is configSTATS_BUFFER_MAX_LENGTH which defaults to 0xFFFF. This is done to ensure that the existing applications do not break. New applications should use the new APIs to avoid memory corruption.

Test Steps

Tested behavior of these APIs for various buffer sizes on Cortex-M7.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aggarg aggarg requested a review from a team as a code owner September 21, 2023 18:07
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (ac5deb1) 93.62% compared to head (dce7c9a) 93.62%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #802   +/-   ##
=======================================
  Coverage   93.62%   93.62%           
=======================================
  Files           6        6           
  Lines        2508     2508           
  Branches      598      598           
=======================================
  Hits         2348     2348           
  Misses        107      107           
  Partials       53       53           
Flag Coverage Δ
unittests 93.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
tasks.c 94.81% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
tasks.c Outdated Show resolved Hide resolved
tasks.c Outdated Show resolved Hide resolved
tasks.c Outdated Show resolved Hide resolved
include/FreeRTOS.h Show resolved Hide resolved
@chinglee-iot
Copy link
Member

Testing this PR with the following snippet without problem

#define LIST_BUFFER_SIZE    1024
static char cTaskListBuffer[ LIST_BUFFER_SIZE ] = { 0 };

/* uxMaxBufferSize doesn't have to be configSTATS_BUFFER_MAX_LENGTH when using
 * vTaskGetRunTimeStats2 or vTaskList2 introduced in this PR. */
tempChar = 0x5a;
uxMaxBufferSize = configSTATS_BUFFER_MAX_LENGTH;
if( LIST_BUFFER_SIZE > uxMaxBufferSize )
{
    memset( &cTaskListBuffer[ uxMaxBufferSize ], tempChar, LIST_BUFFER_SIZE - uxMaxBufferSize );
}

/* Testing the following function one by one. */
vTaskList( cTaskListBuffer );
// vTaskGetRunTimeStats( cTaskListBuffer );
// vTaskGetRunTimeStats2( cTaskListBuffer, uxMaxBufferSize );
// vTaskList2( cTaskListBuffer, uxMaxBufferSize );

/* Ensure the memory after buffer size is not corrupted. */
for( int a = 0; a < ( LIST_BUFFER_SIZE - uxMaxBufferSize ); a++ )
{
    configASSERT( ( cTaskListBuffer[ uxMaxBufferSize + a ] == tempChar ) );
}

aggarg and others added 3 commits September 22, 2023 16:39
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
tony-josi-aws
tony-josi-aws previously approved these changes Sep 22, 2023
chinglee-iot
chinglee-iot previously approved these changes Sep 23, 2023
shubnil
shubnil previously approved these changes Sep 26, 2023
aggarg and others added 2 commits September 26, 2023 14:36
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
actions-user and others added 2 commits September 26, 2023 12:28
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
@sonarcloud
Copy link

sonarcloud bot commented Sep 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@aggarg aggarg merged commit 96d6190 into FreeRTOS:main Sep 26, 2023
17 checks passed
@aggarg aggarg deleted the implement_snprintf branch September 26, 2023 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants