Skip to content

set the last byte in allocated char array to zero. #650

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

Merged
merged 1 commit into from
Nov 3, 2021

Conversation

oleksandr-pavlyk
Copy link
Contributor

@oleksandr-pavlyk oleksandr-pavlyk commented Nov 2, 2021

Set the last byte of new array of chars to 0 to explicitly ensure null-termination.

Noting that the source of the copy, str.c_str() is always null-terminated (see c++-reference), the terminating character of the destination depends on how many bytes the strncpy_s actually copies.

Feel free to dismiss.

@coveralls
Copy link
Collaborator

coveralls commented Nov 2, 2021

Coverage Status

Coverage remained the same at 74.511% when pulling 7985bfe on string-helper-ensure-null-termination into 73ef7b8 on master.

@oleksandr-pavlyk oleksandr-pavlyk force-pushed the string-helper-ensure-null-termination branch 2 times, most recently from 342df7c to 4821508 Compare November 2, 2021 20:54
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the string-helper-ensure-null-termination branch from 4821508 to 7985bfe Compare November 3, 2021 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants