Skip to content

Commit c40a3fb

Browse files
committed
Fix create reference evaluator, bounds checks
Change value type argument handling in create reference evaluator to either match the source evaluator, or cast scalars. https://tracker.physiomeproject.org/show_bug.cgi?id=3835 Fix bounds checks on argument indexes from <0 to <1. https://tracker.physiomeproject.org/show_bug.cgi?id=3836 Some minor formatting fixes and compilation warnings.
1 parent ac7897d commit c40a3fb

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

core/src/SimpleMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ template <typename K, typename V> class SimpleMap
9797

9898
int size()
9999
{
100-
return pairs.size();
100+
return static_cast<int>(pairs.size());
101101
}
102102

103103

core/src/fieldml_api.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ static vector<FmlObjectHandle> getArgumentList( FieldmlSession *session, FmlObje
237237
{
238238
for( set<FmlObjectHandle>::const_iterator i = used.begin(); i != used.end(); i++ )
239239
{
240-
// Performance wise, I am not sure I should remove all elems from
241-
// unbound in used or using find as shown below.
242-
if (unbound.end() == unbound.find(*i))
243-
args.push_back( *i );
240+
// Performance wise, I am not sure I should remove all elems from
241+
// unbound in used or using find as shown below.
242+
if (unbound.end() == unbound.find(*i))
243+
args.push_back( *i );
244244
}
245245
return args;
246246
}
@@ -2158,9 +2158,9 @@ FmlEnsembleValue Fieldml_GetEvaluatorElement( FmlSessionHandle handle, FmlObject
21582158
return -1;
21592159
}
21602160

2161-
if ( ( evaluatorIndex < 0 ) || ( evaluatorIndex > map->size() ) )
2161+
if ( ( evaluatorIndex < 1 ) || ( evaluatorIndex > map->size() ) )
21622162
{
2163-
return -1;
2163+
return -1;
21642164
}
21652165

21662166
return map->getKey( evaluatorIndex - 1 );
@@ -2184,9 +2184,9 @@ FmlObjectHandle Fieldml_GetEvaluator( FmlSessionHandle handle, FmlObjectHandle o
21842184
return FML_INVALID_HANDLE;
21852185
}
21862186

2187-
if ( ( evaluatorIndex < 0 ) || ( evaluatorIndex > map->size() ) )
2187+
if ( ( evaluatorIndex < 1 ) || ( evaluatorIndex > map->size() ) )
21882188
{
2189-
return FML_INVALID_HANDLE;
2189+
return FML_INVALID_HANDLE;
21902190
}
21912191

21922192
return map->getValue( evaluatorIndex - 1 );
@@ -2239,16 +2239,20 @@ FmlObjectHandle Fieldml_CreateReferenceEvaluator( FmlSessionHandle handle, const
22392239
return session->getLastError();
22402240
}
22412241

2242-
if( !checkIsValueType( session, valueType, true, false, false, false ) )
2242+
FmlObjectHandle sourceEvaluatorValueType = Fieldml_GetValueType( handle, sourceEvaluator );
2243+
if( valueType != sourceEvaluatorValueType)
22432244
{
2244-
session->setError( FML_ERR_INVALID_PARAMETER_4, valueType, "Cannot create reference evaluator of this type." );
2245-
return FML_INVALID_HANDLE;
2246-
}
2245+
if( !checkIsValueType( session, valueType, true, false, false, false ) )
2246+
{
2247+
session->setError( FML_ERR_INVALID_PARAMETER_4, valueType, "Cannot create reference evaluator with value type cast to non-scalar non-continuous type." );
2248+
return FML_INVALID_HANDLE;
2249+
}
22472250

2248-
if ( Fieldml_GetTypeComponentCount( handle, valueType ) > 1 )
2249-
{
2250-
session->setError( FML_ERR_INVALID_PARAMETER_4, valueType, "Cannot create reference evaluator, value type is not a scalar type." );
2251-
return FML_INVALID_HANDLE;
2251+
if ( Fieldml_GetTypeComponentCount( handle, valueType ) != 1 )
2252+
{
2253+
session->setError( FML_ERR_INVALID_PARAMETER_4, valueType, "Cannot create reference evaluator with value type cast to non-scalar continuous type." );
2254+
return FML_INVALID_HANDLE;
2255+
}
22522256
}
22532257

22542258
ReferenceEvaluator *referenceEvaluator = new ReferenceEvaluator( name, sourceEvaluator, valueType, false );
@@ -2402,9 +2406,9 @@ FmlObjectHandle Fieldml_GetBindArgument( FmlSessionHandle handle, FmlObjectHandl
24022406
return FML_INVALID_HANDLE;
24032407
}
24042408

2405-
if ( ( bindIndex < 0 ) || ( bindIndex > map->size() ) )
2409+
if ( ( bindIndex < 1 ) || ( bindIndex > map->size() ) )
24062410
{
2407-
return FML_INVALID_HANDLE;
2411+
return FML_INVALID_HANDLE;
24082412
}
24092413

24102414
return map->getKey( bindIndex - 1 );
@@ -2427,9 +2431,9 @@ FmlObjectHandle Fieldml_GetBindEvaluator( FmlSessionHandle handle, FmlObjectHand
24272431
return FML_INVALID_HANDLE;
24282432
}
24292433

2430-
if ( ( bindIndex < 0 ) || ( bindIndex > map->size() ) )
2434+
if ( ( bindIndex < 1 ) || ( bindIndex > map->size() ) )
24312435
{
2432-
return FML_INVALID_HANDLE;
2436+
return FML_INVALID_HANDLE;
24332437
}
24342438

24352439
return map->getValue( bindIndex - 1 );
@@ -3675,7 +3679,7 @@ FmlObjectHandle Fieldml_GetDataSource( FmlSessionHandle handle, FmlObjectHandle
36753679

36763680
return FML_INVALID_HANDLE;
36773681
}
3678-
3682+
36793683

36803684
FmlObjectHandle Fieldml_GetKeyDataSource( FmlSessionHandle handle, FmlObjectHandle objectHandle )
36813685
{
@@ -3725,7 +3729,7 @@ int Fieldml_GetDataSourceCount( FmlSessionHandle handle, FmlObjectHandle objectH
37253729
return resource->dataSources.size();
37263730
}
37273731

3728-
3732+
37293733
FmlObjectHandle Fieldml_GetDataSourceByIndex( FmlSessionHandle handle, FmlObjectHandle objectHandle, int index )
37303734
{
37313735
FieldmlSession *session = FieldmlSession::handleToSession( handle );
@@ -3781,7 +3785,7 @@ FmlObjectHandle Fieldml_GetDataSourceResource( FmlSessionHandle handle, FmlObjec
37813785
return session->region->getNamedObject( source->resource->name );
37823786
}
37833787

3784-
3788+
37853789
char * Fieldml_GetArrayDataSourceLocation( FmlSessionHandle handle, FmlObjectHandle objectHandle )
37863790
{
37873791
FieldmlSession *session = FieldmlSession::handleToSession( handle );

core/src/fieldml_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ FmlObjectHandle Fieldml_GetIndexEvaluator( FmlSessionHandle handle, FmlObjectHan
991991
* Creates a reference evaluator. Reference evaluators delegate their evaluation directly to another evaluator, but can bind
992992
* argument evaluators before doing so.
993993
*
994-
* \note Currently, the value type must be a scalar continuous type.
994+
* \note The value type may be either that of the source evaluator, OR for a scalar continuous source evaluator, it may be 'cast' to any scalar continuous type.
995995
*
996996
* \see Fieldml_GetReferenceSourceEvaluator
997997
*/

0 commit comments

Comments
 (0)