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

Add cast to xQueueGenericCreate to allow queue creation for 8-bit ports #1152

Closed

Conversation

kar-rahul-aws
Copy link
Member

Description

This PR addresses the bug which fails to create Queues with more element bytes than UBaseType_t for 8-bit ports.
The fault is caused by the size of UBaseType_t on 8-bit ports which is uint8_t, meaning its maximum value is 255. This reduces the max "valid" size to a very small number.

Bigger CPUs like SAM/ARM which have UBaseType_t defined as uint16_t/uint32_t do not suffer this issue because such a large queues are not allocated in practice.

The fix is adding the case UBaseType_t to the RHS of this check

Test Steps

Run the Posix_GCC demo with these changes:
main_full.c

int main_full( void )
{
    QueueHandle_t result1 = xQueueCreate(64, 4);
    if( result1 == NULL )
    {
        printf( "Queue 1 creation failed.\r\n" );
    }
    else
    {
        printf( "Queue 1 creation succeeded.\r\n" );
    }

    QueueHandle_t result2 = xQueueCreate(10, 2);
    if( result2 == NULL )
    {
        printf( "Queue 2 creation failed.\r\n" );
    }
    else
    {
        printf( "Queue 2 creation succeeded.\r\n" );
    }
}

O/p for Posix port

Queue 1 creation succeeded.
Queue 2 creation succeeded.

To simulate the 8-bit port behavior, this line in queue.c is changed to :

( uint8_t ) ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) )

Output :
Queue Creation fails and this configASSERT is triggered.

When this patch is applied :-

( uint8_t ) ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) )

Output:

Queue 1 creation succeeded.
Queue 2 creation succeeded.

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

#1151

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

@kar-rahul-aws kar-rahul-aws requested a review from a team as a code owner September 29, 2024 08:56
@kar-rahul-aws kar-rahul-aws marked this pull request as draft September 29, 2024 08:56
Copy link

sonarcloud bot commented Sep 29, 2024

@neboskreb
Copy link

The suggested change does NOT fix the issue. It does not expand the size of LHS, meaning that it is still 8 bit on 8-bit platforms; shrinking the size of RHS to the same 8 bits does NOT improve the situation.

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.

2 participants