Skip to content

pointer aliasing in ImfFloatToHalf #5

@k3f42

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,

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