-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Clean up ex-malloc() use of CHIPMem.h #3222
Clean up ex-malloc() use of CHIPMem.h #3222
Conversation
#### Problem As part of heap memory management, a recent change (project-chip#3143) replaced malloc()-family calls one-for-one with their "CHIPMem.h" equivalents, but a one-to-one replacement is not always ideal. #### Summary of Changes - Use ScopedMemoryBuffer instead where possible. - Added ScopedMemoryString, since this is a common case. - Some addition safety checks.
src/lib/support/CHIPMemString.h
Outdated
{ | ||
if (dest) | ||
{ | ||
memcpy(dest, source, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any issues if source is shorter than length? Maybe we could use strncpy internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to say no (NUL in the source is fine, NUL not in the source is fine) but there is one case where memcpy would break (NUL-terminated source closely followed by dangerous addresses).
Problem
As part of heap memory management, a recent change (#3143) replaced
malloc()-family calls one-for-one with their "CHIPMem.h" equivalents,
but a one-to-one replacement is not always ideal.
Summary of Changes