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

[#491] Ensure enum string literals are null terminated #538

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

orecham
Copy link
Contributor

@orecham orecham commented Dec 2, 2024

Notes for Reviewer

Fix bug where string literals were not null terminated.

Unrelated: Also fix typo in existing assert_that message.

Pre-Review Checklist for the PR Author

  1. Add sensible notes for the reviewer
  2. PR title is short, expressive and meaningful
  3. Relevant issues are linked in the References section
  4. Every source code file has a copyright header with SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Branch follows the naming format (iox2-123-introduce-posix-ipc-example)
  6. Commits messages are according to this guideline
  7. Tests follow the best practice for testing
  8. Changelog updated in the unreleased section including API breaking changes
  9. Assign PR to reviewer
  10. All checks have passed (except task-list-completed)

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Unit tests have been written for new behavior
  • Public API is documented
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

Closes #491

Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 79.10%. Comparing base (949d2e0) to head (32e86bd).

Files with missing lines Patch % Lines
iceoryx2-bb/derive-macros/src/lib.rs 0.00% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #538      +/-   ##
==========================================
- Coverage   79.13%   79.10%   -0.04%     
==========================================
  Files         202      202              
  Lines       24815    24819       +4     
==========================================
- Hits        19638    19632       -6     
- Misses       5177     5187      +10     
Files with missing lines Coverage Δ
iceoryx2-bb/derive-macros/src/lib.rs 0.00% <0.00%> (ø)

... and 9 files with indirect coverage changes

@@ -171,6 +175,7 @@ pub fn string_literal_derive(input: TokenStream) -> TokenStream {
c => c.to_ascii_lowercase(),
})
.collect::<String>();
enum_string_literal.push('\0');
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I also run into this issue.

///
/// let v2 = MyEnum::VariantTwo;
/// assert_eq!(v2.as_str_literal(), "variant two");
/// assert_eq!(v2.as_str_literal(), "variant two\0");
Copy link
Contributor

Choose a reason for hiding this comment

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

In rust strings are never null terminated it is only typical for ffi bindings. Should we move string_literal_derive into iceoryx2-ffi since it is only used there?

@@ -118,10 +118,10 @@ pub fn placement_default_derive(input: TokenStream) -> TokenStream {
/// }
///
/// let v1 = MyEnum::VariantOne;
/// assert_eq!(v1.as_str_literal(), "custom variant one");
/// assert_eq!(v1.as_str_literal(), "custom variant one\0");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// assert_eq!(v1.as_str_literal(), "custom variant one\0");
/// assert_eq!(v1.as_str_literal(), c"custom variant one");

Can the same be made in the macro? Something like c#enum_string_literal

@orecham orecham self-assigned this Dec 3, 2024
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.

Provide error description strings via C/C++ API
3 participants