Archived issue #0024534
Improve design of Image_PixMap class
Description
This issue is highlighed by GCC compiler warning on breakage of C strict aliasing rules in type conversion, see #0024252:
Image_PixMap.hxx:247: warning: dereferencing type-punned pointer will break strict-aliasing rules
The actual problem seems to be poor design of Image_PixMap class: it has a field of the type Image_PixMapData<Standard_Byte> but provides a means to address it as if it had different type (via its methods EditData(), ReadData(), Value()). This is obviously incorrect.
One possibility to fix it could be providing method to convert between Image_PixMapData<> classes with different template argument, and make correct instance when needed (possibly creating several instances sharing the same buffer).
Image_PixMap.hxx:247: warning: dereferencing type-punned pointer will break strict-aliasing rules
The actual problem seems to be poor design of Image_PixMap class: it has a field of the type Image_PixMapData<Standard_Byte> but provides a means to address it as if it had different type (via its methods EditData(), ReadData(), Value()). This is obviously incorrect.
One possibility to fix it could be providing method to convert between Image_PixMapData<> classes with different template argument, and make correct instance when needed (possibly creating several instances sharing the same buffer).
Public activity
3 archived notes
Participants are labeled by their role within this record.
Patch for OCCT and Products is ready for review in branch CR24534_1 (based on CR24405).
Branch CR24534_1 reviewed in occt and occt-products without remarks, ready for testing.
Dear Commenter 2,
OCCT and Products branch CR24534_1 was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 24 (27 on master) - 3 warnings in inc/Image_PixMap.hxx were removed
Windows: 0 (0 on master)
products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 395027512 / 350990000
Total CPU difference: 58587.06999999985 / 50414.12000000013
Testing on Windows:
Total MEMORY difference: 437939848 / 380569632
Total CPU difference: 35148.125 / 36389.671875
There are no differences in images found by testdiff.
OCCT and Products branch CR24534_1 was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 24 (27 on master) - 3 warnings in inc/Image_PixMap.hxx were removed
Windows: 0 (0 on master)
products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 395027512 / 350990000
Total CPU difference: 58587.06999999985 / 50414.12000000013
Testing on Windows:
Total MEMORY difference: 437939848 / 380569632
Total CPU difference: 35148.125 / 36389.671875
There are no differences in images found by testdiff.
Related records