Skip to content

Conversation

@Gnorkus
Copy link

@Gnorkus Gnorkus commented Dec 4, 2025

Check for non-zero string size before copying.

Check for non-zero string size before copying.
@Gnorkus Gnorkus requested a review from a team as a code owner December 4, 2025 16:33
@github-actions github-actions bot added the component: cscore CameraServer library label Dec 4, 2025
std::memcpy(write, str.data(), str.size());
size_t n = str.size();
char* write = WPI_AllocateString(output, n);
if (n>0)
Copy link
Member

@calcmogul calcmogul Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our style guide requires curly braces on control flow statements.

@KangarooKoala
Copy link
Contributor

What's the purpose of these check? It seems like this check is unnecessary: See https://stackoverflow.com/questions/3751797/can-i-call-memcpy-and-memmove-with-number-of-bytes-set-to-zero and others.

@ThadHouse
Copy link
Member

What's the purpose of these check? It seems like this check is unnecessary: See https://stackoverflow.com/questions/3751797/can-i-call-memcpy-and-memmove-with-number-of-bytes-set-to-zero and others.

That post is only if both pointers are valid. Memcpy and memmove are UB if any of the pointers are null. Which an empty string view is.

@KangarooKoala
Copy link
Contributor

Ah, I missed that empty string views have nullptr .data().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: cscore CameraServer library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants