Skip to content

Conversation

dpfrey
Copy link
Contributor

@dpfrey dpfrey commented May 21, 2021

The memset of the m_buffers variable was not being done correctly.

For example, consider:
ERPC_DEFAULT_BUFFERS_COUNT=3
ERPC_DEFAULT_BUFFER_SIZE=24

ERPC_BUFFER_SIZE_UINT8 would be (24 + 8 - 1) = 31
ERPC_BUFFER_SIZE_UINT64 would be (31 / 8) = 3
The size of the memset would be (3 * 31) = 93
The size of the array would be (8 * 3 * 3) = 72

So in this example, the memset would go (93 - 72) = 21 bytes past the
end of the array.

The memset of the m_buffers variable was not being done correctly.

For example, consider:
  ERPC_DEFAULT_BUFFERS_COUNT=3
  ERPC_DEFAULT_BUFFER_SIZE=24

ERPC_BUFFER_SIZE_UINT8 would be (24 + 8 - 1) = 31
ERPC_BUFFER_SIZE_UINT64 would be (31 / 8) = 3
The size of the memset would be (3 * 31) = 93
The size of the array would be (8 * 3 * 3) = 72

So in this example, the memset would go (93 - 72) = 21 bytes past the
end of the array.
@peterhinson
Copy link
Contributor

I just came across this too, thanks for the PR. I think there's another bug in this code related to m_freeBufferBitmap:

(void)memset(m_freeBufferBitmap, 0xff, ERPC_DEFAULT_BUFFERS_COUNT >> 3);

Should be:

(void)memset(m_freeBufferBitmap, 0xff, (ERPC_DEFAULT_BUFFERS_COUNT >> 3)+1U); // or sizeof(m_freeBufferBitmap)

Since ERPC_DEFAULT_BUFFERS_COUNT>>3 will equal 0 if ERPC_DEFAULT_BUFFERS_COUNT is under 8.

The array m_freeBufferBitmap was larger than necessary when
ERPC_DEFAULT_BUFFERS_COUNT is divisible by 8. This is not a bug, but it
is a bit inefficient. The memset of m_freeBufferBitmap was shorter than
the length of the array which had the effect of pre-allocating
(ERPC_DEFAULT_BUFFERS_COUNT % 8) of the buffers.

Thanks to Peter Hinson for identifying this issue.
@dpfrey
Copy link
Contributor Author

dpfrey commented May 28, 2021

Good point @peterhinson. I have added a second commit that I believe also addresses this issue.

@MichalPrincNXP MichalPrincNXP self-requested a review June 24, 2021 12:19
@MichalPrincNXP MichalPrincNXP self-assigned this Jun 24, 2021
@MichalPrincNXP
Copy link
Member

Good point, great, thank you @dpfrey , @peterhinson . Again, because the internal testing for the v1.8.1 release is almost finished, I would rather integrate this PR after the release, i.e. in about 3w. Thank you.

@MichalPrincNXP MichalPrincNXP merged commit 313a297 into EmbeddedRPC:develop Jul 19, 2021
@MichalPrincNXP
Copy link
Member

Thanks a lot!

@dpfrey dpfrey deleted the pr_m_buffers_memset branch July 19, 2021 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants