MantisBT - Open CASCADE
View Issue Details
0026377Open CASCADE[OCCT] OCCT:Foundation Classespublic2015-06-28 13:462016-04-20 15:51
[OCCT] 7.0.0[OCCT] 7.0.0 
0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous
As pointed out by Roman Lygin, passing Handle object as argument to function accepting non-const reference to handle to base type may be dangerous, as the handle can be modified by that function, and there is no guarantee that the new object pointed by it will be compatible with the original handle type.


  Handle(TDataStd_Real) A;
  if (Label.FindAttribute (TDataStd_Integer::GetID(), A)) {
    // A is used as TData_Std_Real, while the object pointed by it is TDataStd_Integer

It would be good to have protection in this situation, to ensure that either exception is raised or at least handle is nullified if it is assigned non-compatible type. This should be possible when new handles are implemented in the frames of 0024023
Not required
No tags attached.
related to 0024023closed abv Open CASCADE Revamp the OCCT Handle 
related to 0027104closed abv Community DownCast() cannot return null for mismatched handle 
related to 0027111closed abv Community Add generalized copy constructor in handle class for old compilers 
related to 0027185closed bugmaster Open CASCADE Data Exchange - IGES - incorrect reading of DE for undefined entity 
Issue History
2015-06-28 13:46abvNew Issue
2015-06-28 13:46abvAssigned To => abv
2015-06-28 13:57abvRelationship addedrelated to 0024023
2015-06-29 07:08gitNote Added: 0042518
2015-12-14 22:39abvTarget Version7.0.0 => 7.1.0
2016-01-21 16:30Roman LyginRelationship addedrelated to 0026497
2016-01-21 16:31Roman LyginRelationship deletedrelated to 0026497
2016-01-21 16:31Roman LyginRelationship addedrelated to 0027104
2016-01-25 20:36Roman LyginRelationship addedrelated to 0027111
2016-02-18 19:00abvRelationship addedrelated to 0027185
2016-02-19 11:02bugmasterStatusnew => resolved
2016-02-19 11:02bugmasterSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=13010#r13010
2016-02-19 11:02bugmasterSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=13011#r13011
2016-02-19 11:03bugmasterAssigned Toabv => bugmaster
2016-02-19 11:03bugmasterStatusresolved => reviewed
2016-02-19 11:03bugmasterNote Added: 0050997
2016-02-19 11:03bugmasterStatusreviewed => tested
2016-02-19 11:21abvTarget Version7.1.0 => 7.0.0
2016-02-21 08:52abvChangeset attached => occt master aa00364d
2016-02-21 08:52abvAssigned Tobugmaster => abv
2016-02-21 08:52abvStatustested => verified
2016-02-21 08:52abvResolutionopen => fixed
2016-04-17 15:06gitNote Added: 0053250
2016-04-20 15:42aivFixed in Version => 7.0.0
2016-04-20 15:51aivStatusverified => closed

2015-06-29 07:08   
Branch CR26377 has been created by abv.

SHA-1: 87f01da0abf201904b5ae6b1c06b98492aa94ad9

Detailed log of new commits:

Author: abv
Date: Sun Jun 28 13:52:12 2015 +0300

    0026377: Passing Handle objects as arguments to functions as non-const reference to base type is dangerous
    Function SafeUpCast() added in opencascade::handle class to allow safe passing of handle as argument to functions accepting non-const reference to handle of base type.
    Operator of cast to non-const reference is removed.
2016-02-19 11:03   
Tested with CR26711_6
2016-04-17 15:06   
Branch CR26377 has been deleted by kgv.

SHA-1: 87f01da0abf201904b5ae6b1c06b98492aa94ad9