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

atchops_base64_encode: return null-terminated buffer #534

Closed
XavierChanth opened this issue Jan 24, 2025 · 1 comment
Closed

atchops_base64_encode: return null-terminated buffer #534

XavierChanth opened this issue Jan 24, 2025 · 1 comment

Comments

@XavierChanth
Copy link
Member

atchops_base64_encode requires a pre-allocated buffer, which is an anti-pattern for returning null-terminated strings. We can coerce our own null-terminated string by allocating one byte longer than we pass as the buffer size into this function. The style for this function should change to not require input or output parameters, and the function should determine and allocate the buffer itself.

@XavierChanth
Copy link
Member Author

We have a function called atchops_base64_encoded_size which provides the size required for a buffer to be encoded in base64. If you pass that size in to atchops_base64_encode you will get a buffer which is not null-terminated, but if you pass a size which is larger than that by at least one byte, then you will get a null-terminated buffer.

I believe this to be the best of both worlds.

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

No branches or pull requests

1 participant