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

pointer aliasing in ImfFloatToHalf #5

Open
k3f42 opened this issue Apr 11, 2015 · 0 comments
Open

pointer aliasing in ImfFloatToHalf #5

k3f42 opened this issue Apr 11, 2015 · 0 comments

Comments

@k3f42
Copy link

k3f42 commented Apr 11, 2015

there are 2 bad aliasing in the ImfFloatToHalf (float f, ImfHalf *h) function, making compilers and analyzers cry as it does not follow the aliasing rules... easily fixed with a memcpy:

short half = FloatToHalf( (int)&f );
is replaced by
int x;
memcpy((void *)&x,(const void *)&f,sizeof(float));
short half = FloatToHalf(x);
(same for ImfHalf cast).

Assembly generated is exactly the same (on my machine) but compiler is happy and code is now safe if aggressive optimization is turn on.

Cheers,

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

No branches or pull requests

1 participant