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

Improvements to C++ MakePath/MakePathD #401

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

jschuh
Copy link
Contributor

@jschuh jschuh commented Feb 6, 2023

Thanks for pulling in PR #398, but I think it may have an error. To explain, the static_assert in my original PR is evaluated only at compile-time, and will cause the build to terminate on an odd number of list values. However, the altered version allows the compiler to emit a MakePath with an odd numbered list, which when called would result in an out-of-bounds read from list. This PR fixes the bug by adding back the static_assert (I figure it's better to have the compiler simply prevent the bug instead of having to deal with one that appears at run-time).

Also, MakePath/MakePathD in PR #398 wouldn't accept a dynamically allocated list argument, but in retrospect it probably should have since the versions for other languages do. So, I added vector accepting versions (which use DoError since they have to check the length at runtime). To simplify the code I also moved the vector initialization into the details::MakePathGeneric helper function.

One other thing I should probably highlight is that the implementation of details::MakePathGeneric is structured to maximize what the compiler can evaluate at compile-time rather than run-time. There are certainly other ways to write it, but in my experience this should minimize the amount of unnecessary runtime code that gets generated.

* Accept a vector argument to MakePath/MakePathD
* Force a compiler error on an unpaired initializer_list
* Fix OOB read in MakePath/MakePathD
@AngusJohnson AngusJohnson merged commit e056382 into AngusJohnson:main Feb 6, 2023
@AngusJohnson
Copy link
Owner

Great help. Thanks.

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.

2 participants