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

Make function parameters in iface_mapper const when possible #545

Merged
merged 2 commits into from
Mar 28, 2023

Conversation

aloisklink
Copy link
Contributor

Make all the function parameters in src/utils/iface_mapper.c const when possible.

This PR also removes the unnecessary memcpy() calls in iface_mapper.c.

memcpy() is worse than using struct assignment, since:

  1. It also copies padding bytes, which do not need to be copied.
  2. On CHERI, memcpy() needs to copy the capability tags of any pointer type, which makes memcpy() far more complicated.
  3. Using memcpy() increases the risk of memory bugs, since we need to manually specify types and the number of bytes to copy.

Make all function parameters in `iface_mapper.c` `const` when possible.
Remove the unnecessary memcpy() calls in `iface_mapper.c`.

`memcpy()` is worse than using struct assignment, since:

1. It also copies padding bytes, which do not need to be copied.
2. On CHERI, `memcpy()` needs to copy the capability tags of any
   pointer type, which makes `memcpy()` far more complicated.
3. Using `memcpy()` increases the risk of memory bugs, since we need
   to manually specify types and the number of bytes to copy.
@aloisklink aloisklink added the refactor Refactoring code label Mar 27, 2023
@aloisklink aloisklink added this to the CheriBSD Support milestone Mar 27, 2023
@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Merging #545 (628731e) into main (1e3bfe4) will increase coverage by 0.00%.
The diff coverage is 67.74%.

@@           Coverage Diff           @@
##             main     #545   +/-   ##
=======================================
  Coverage   54.14%   54.14%           
=======================================
  Files         144      144           
  Lines       21036    21039    +3     
=======================================
+ Hits        11389    11392    +3     
  Misses       9647     9647           
Impacted Files Coverage Δ
src/utils/iface_mapper.c 51.32% <67.74%> (+0.24%) ⬆️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@aloisklink aloisklink added this pull request to the merge queue Mar 28, 2023
Merged via the queue into main with commit 780f2b7 Mar 28, 2023
@aloisklink aloisklink deleted the refactor/make-iface_mapper-params-const branch March 28, 2023 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactoring code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants