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

Remove undefined behaviour in Vector3 and QAngle #616

Open
ASpoonPlaysGames opened this issue Dec 18, 2023 · 0 comments
Open

Remove undefined behaviour in Vector3 and QAngle #616

ASpoonPlaysGames opened this issue Dec 18, 2023 · 0 comments

Comments

@ASpoonPlaysGames
Copy link
Contributor

union Vector3
{
struct
{
float x;
float y;
float z;
};
float raw[3];
void MakeValid()
{
for (auto& fl : raw)
if (std::isnan(fl))
fl = 0;
}
// todo: more operators maybe
bool operator==(const Vector3& other)
{
return x == other.x && y == other.y && z == other.z;
}
};

This code seems to think that accessing x, y, z and raw interchangeably is defined behaviour. It is undefined behaviour to access a member of a union that was not the most recently set.

https://eel.is/c++draft/class.union#general-2
https://eel.is/c++draft/class.mem#general-23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant