Skip to content

Commit 48f1285

Browse files
committed
improve stepattr copy constructor
uses shallow copy, so access violations are possible
1 parent bcd0147 commit 48f1285

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

src/clstepcore/STEPattribute.inline.cc

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,63 @@
1212

1313
#include <assert.h>
1414
#include <STEPattribute.h>
15+
#include <STEPaggregate.h>
1516
#include <sdai.h>
1617
#include <ExpDict.h>
1718
#include "sc_memmgr.h"
1819

19-
/// This is needed so that STEPattribute's can be passed as references to inline functions
20+
/// This is needed so that STEPattribute's can be passed as references to inline functions
21+
/// NOTE this code only does shallow copies. It may be necessary to do more, in which case
22+
/// the destructor and assignment operator will also need examined.
2023
STEPattribute::STEPattribute( const STEPattribute & a )
21-
: _derive( false ), _redefAttr( 0 ), aDesc( a.aDesc ), refCount( 0 ) {}
24+
: _derive( a._derive ), _redefAttr( a._redefAttr ), aDesc( a.aDesc ), refCount( a.refCount ) {
25+
26+
//the following comes from STEPattribute::ShallowCopy
27+
switch( NonRefType() ) {
28+
case INTEGER_TYPE:
29+
*ptr.i = *( a.ptr.i );
30+
break;
31+
32+
case BINARY_TYPE:
33+
*( ptr.b ) = *( a.ptr.b );
34+
break;
35+
36+
case STRING_TYPE:
37+
*( ptr.S ) = *( a.ptr.S );
38+
break;
39+
40+
case REAL_TYPE:
41+
case NUMBER_TYPE:
42+
*ptr.r = *( a.ptr.r );
43+
break;
44+
45+
case ENTITY_TYPE:
46+
ptr.c = a.ptr.c; //NOTE may need to deep copy
47+
break;
48+
49+
case AGGREGATE_TYPE:
50+
case ARRAY_TYPE: // DAS
51+
case BAG_TYPE: // DAS
52+
case SET_TYPE: // DAS
53+
case LIST_TYPE: // DAS
54+
ptr.a = a.ptr.a; //NOTE may need to deep copy
55+
break;
56+
57+
case SELECT_TYPE:
58+
*ptr.sh = *( a.ptr.sh );
59+
break;
60+
61+
case ENUM_TYPE:
62+
case BOOLEAN_TYPE:
63+
case LOGICAL_TYPE:
64+
ptr.e->put( a.ptr.e->asInt() );
65+
break;
66+
67+
default:
68+
*ptr.u = *( a.ptr.u );
69+
break;
70+
}
71+
}
2272

2373
/// INTEGER
2474
STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Integer * p )

src/clstepcore/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ function(add_stepcore_test name libs)
1919
endfunction(add_stepcore_test name libs)
2020

2121
add_stepcore_test( "SupertypesIterator" "stepcore;steputils;stepeditor;stepdai;base" ) #all these libs are necessary?
22-
add_stepcore_test( "copy_assign_STEPattribute" "stepcore;steputils;stepeditor;stepdai;base" )
22+
add_stepcore_test( "operators_STEPattribute" "stepcore;steputils;stepeditor;stepdai;base" )

0 commit comments

Comments
 (0)