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

ByteValue: safer and more effitient memory usage #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MadVitaliy
Copy link
Contributor

Firstly, the user can initialize a ByteValue object with nullptr and non-zero length which may lead to nullprt dereference.

Secondly, if the passed length is odd, already initialized "Internal" vector is resized, which most likely causes memory reallocation and copy. Instead, memory can be allocated only once after a proper length calculated. On top of that, "memcpy" might be faster than than initializing with "Internal(array, array+vlm)". It safe as Internal is just a vector of chars.

To sum up, taking into consideration that ByteValue is oftenly used, I believe these changes are worth to be taken.

@MadVitaliy
Copy link
Contributor Author

Also, these change rid of some -Werror=nonnull warnings.

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.

1 participant