MantisBT - Open CASCADE
View Issue Details
0029170Open CASCADE[OCCT] OCCT:Codingpublic2017-09-30 21:052018-06-29 21:19
[OCCT] 7.3.0[OCCT] 7.3.0 
Not required
0029170: GCC 7.1 warnings -Wstrict-aliasing in Graphic3d_ArrayOfPrimitives.hxx
When OCCT is built with GCC 7.1 (with MinGw-64), it reports multiple warnings "dereferencing type-punned pointer will break strict aliasing rules [-Wstrict-aliasing]" in two methods Graphic3d_ArrayOfPrimitives::SetVertexColor().

The reason is that reinterpret_cast<> is used to cast pointers of types where both initial and target types are different from char*.
Compile with GCC 7.1 (MinGW-64)
No tags attached.
Issue History
2017-09-30 21:05abvNew Issue
2017-09-30 21:05abvAssigned To => kgv
2017-09-30 21:35gitNote Added: 0071086
2017-09-30 21:36gitNote Added: 0071087
2017-09-30 21:50abvNote Added: 0071088
2017-09-30 21:50abvStatusnew => resolved
2017-09-30 21:50abvSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=17784#r17784
2017-09-30 21:54kgvNote Added: 0071089
2017-09-30 21:54kgvAssigned Tokgv => bugmaster
2017-09-30 21:54kgvStatusresolved => reviewed
2017-10-01 13:58abvNote Edited: 0071088bug_revision_view_page.php?bugnote_id=71088#r17788
2017-10-01 21:13gitNote Added: 0071101
2017-10-01 22:08gitNote Added: 0071104
2017-10-03 09:47bugmasterNote Added: 0071138
2017-10-03 09:47bugmasterStatusreviewed => tested
2017-10-03 09:51bugmasterTest case number => Not required
2017-10-06 14:55bugmasterChangeset attached => occt master 6a657c92
2017-10-06 14:55bugmasterStatustested => verified
2017-10-06 14:55bugmasterResolutionopen => fixed
2017-10-14 12:20gitNote Added: 0071476
2018-06-29 21:15aivFixed in Version => 7.3.0
2018-06-29 21:19aivStatusverified => closed

2017-09-30 21:35   
Branch CR29170 has been created by abv.

SHA-1: c44ce27fec1b39d4a8361a0ef1de67d779101855

Detailed log of new commits:

Author: abv
Date: Sat Sep 30 21:35:05 2017 +0300

    0029170: GCC 7.1 warnings -Wstrict-aliasing in Graphic3d_ArrayOfPrimitives.hxx
    Methods Graphic3d_ArrayOfPrimitives::SetVertexColor() accepting color as three double rgb values and Graphic3d_Vec4ub object are refactored to avoid using reinterpret_cast between pointers to complex types.
    Similar correction is made in ViewerTest_ObjectCommands.cxx (static function VDrawSphere).
2017-09-30 21:36   
Branch CR29170 has been updated forcibly by abv.

SHA-1: 215dbbde92b87dd5cd67f6019c48835339c1675d
2017-09-30 21:50   
(edited on: 2017-10-01 13:58)
Fix is is pushed to CR29170, please review.

Please note that method SetVertexColor (const Standard_Integer theIndex, const Standard_Integer theColor32), unlike other similar methods around, does not update myAttribs->NbElements at the end. Is that correct?

In general, the whole design of this class looks quite dangerous, as it operates directly with array of data which elements can have different content and size, without proper consistency checks. It is quite strange that methods like SetVertexColor behave differently in the case if index is out of range (exception is raised) and when either myAttribs data array is Null or data being set is not available (they do nothing).

It seems that this class should be redesigned as template, to make a choice of format of the stored data known at compile time, and enable static type checks. It conversion to template is not feasible, then it is not clear why so many large methods are implemented as inline -- they should rather be moved to CXX.

2017-09-30 21:54   
Please test the patch.
2017-10-01 21:13   
Branch CR29170 has been updated forcibly by abv.

SHA-1: c7e8ccd0841fe4d055d99f0b07a78a0f98807af2
2017-10-01 22:08   
Branch CR29170 has been updated forcibly by abv.

SHA-1: 283f861cd437469319a3853072c5b832542adc78
2017-10-03 09:47   
Combination -
OCCT branch : CR29170 SHA-1: 283f861cd437469319a3853072c5b832542adc78
Products branch : master
was compiled on Linux, MacOS and Windows platforms and tested on optimize mode. [^] [^]

Number of compiler warnings:
Mingw 5 (151 master)

No regressions/differences

CPU differences:
No differences that require special attention

Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
2017-10-14 12:20   
Branch CR29170 has been deleted by kgv.

SHA-1: 283f861cd437469319a3853072c5b832542adc78