Skip to content

pointer aliasing in ImfFloatToHalf #5

Description

@k3f42

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,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions