avoid using strncpy in STEPFile::schemaName()
This commit is contained in:
+25
-41
@@ -1314,8 +1314,7 @@ STEPfile::CreateInstance( istream & in, ostream & out ) {
|
||||
std::string objnm;
|
||||
|
||||
char c;
|
||||
char schnm[BUFSIZ];
|
||||
schnm[0] = '\0';
|
||||
std::string schnm;
|
||||
|
||||
int fileid = -1;
|
||||
SCLP23( Application_instance_ptr ) * scopelist = 0;
|
||||
@@ -1395,8 +1394,8 @@ STEPfile::CreateInstance( istream & in, ostream & out ) {
|
||||
<< endl;
|
||||
return ENTITY_NULL;
|
||||
} else {
|
||||
schemaName( schnm );
|
||||
obj = reg().ObjCreate( objnm.c_str(), schnm );
|
||||
schnm = schemaName();
|
||||
obj = reg().ObjCreate( objnm.c_str(), schnm.c_str() );
|
||||
if( obj == ENTITY_NULL ) {
|
||||
// This will be the case if objnm does not exist in the reg.
|
||||
result.UserMsg( "Unknown ENTITY type" );
|
||||
@@ -1548,8 +1547,7 @@ STEPfile::CreateSubSuperInstance( istream & in, int fileid, ErrorDescriptor & e
|
||||
SCLP23( Application_instance ) * obj = ENTITY_NULL;
|
||||
|
||||
char c;
|
||||
char schnm[BUFSIZ];
|
||||
schnm[0] = '\0';
|
||||
std::string schnm;
|
||||
|
||||
std::string buf; // used to hold the simple record that is read
|
||||
ErrorDescriptor err; // used to catch error msgs
|
||||
@@ -1584,9 +1582,9 @@ STEPfile::CreateSubSuperInstance( istream & in, int fileid, ErrorDescriptor & e
|
||||
}
|
||||
}
|
||||
entNmArr[enaIndex] = 0;
|
||||
schemaName( schnm );
|
||||
schnm = schemaName();
|
||||
|
||||
obj = new STEPcomplex( &_reg, ( const std::string ** )entNmArr, fileid, schnm );
|
||||
obj = new STEPcomplex( &_reg, ( const std::string ** )entNmArr, fileid, schnm.c_str() );
|
||||
|
||||
if( obj->Error().severity() <= SEVERITY_WARNING ) {
|
||||
// If obj is not legal, record its error info and delete it:
|
||||
@@ -1753,8 +1751,7 @@ STEPfile::ReadInstance( istream & in, ostream & out, std::string & cmtStr,
|
||||
std::string tmpbuf;
|
||||
char errbuf[BUFSIZ];
|
||||
errbuf[0] = '\0';
|
||||
char currSch[BUFSIZ];
|
||||
currSch[0] = '\0';
|
||||
std::string currSch;
|
||||
std::string objnm;
|
||||
|
||||
char c;
|
||||
@@ -1825,12 +1822,12 @@ STEPfile::ReadInstance( istream & in, ostream & out, std::string & cmtStr,
|
||||
in.putback( c );
|
||||
}
|
||||
|
||||
schemaName( currSch );
|
||||
currSch = schemaName();
|
||||
|
||||
//check for subtype/supertype record
|
||||
if( c == '(' ) {
|
||||
// TODO
|
||||
sev = obj->STEPread( fileid, idIncrNum, &instances(), in, currSch,
|
||||
sev = obj->STEPread( fileid, idIncrNum, &instances(), in, currSch.c_str(),
|
||||
useTechCor );
|
||||
|
||||
ReadTokenSeparator( in, &cmtStr );
|
||||
@@ -1877,7 +1874,7 @@ STEPfile::ReadInstance( istream & in, ostream & out, std::string & cmtStr,
|
||||
// NOTE: this function is called for all FileTypes
|
||||
// (WORKING_SESSION included)
|
||||
|
||||
sev = obj->STEPread( fileid, idIncrNum, &instances(), in, currSch,
|
||||
sev = obj->STEPread( fileid, idIncrNum, &instances(), in, currSch.c_str(),
|
||||
useTechCor );
|
||||
|
||||
ReadTokenSeparator( in, &cmtStr );
|
||||
@@ -2199,16 +2196,13 @@ void STEPfile::WriteHeaderInstanceFileSchema( ostream & out ) {
|
||||
***************************/
|
||||
|
||||
void STEPfile::WriteData( ostream & out, int writeComments ) {
|
||||
char currSch[BUFSIZ];
|
||||
currSch[0] = '\0';
|
||||
|
||||
std::string currSch = schemaName();
|
||||
out << "DATA;\n";
|
||||
|
||||
schemaName( currSch );
|
||||
int n = instances().InstanceCount();
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->STEPwrite( out, currSch, writeComments );
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->STEPwrite( out, currSch.c_str(), writeComments );
|
||||
}
|
||||
|
||||
out << "ENDSEC;\n";
|
||||
@@ -2217,20 +2211,16 @@ void STEPfile::WriteData( ostream & out, int writeComments ) {
|
||||
/***************************
|
||||
***************************/
|
||||
|
||||
void
|
||||
STEPfile::WriteValuePairsData( ostream & out, int writeComments, int mixedCase ) {
|
||||
char currSch[BUFSIZ];
|
||||
currSch[0] = '\0';
|
||||
schemaName( currSch );
|
||||
void STEPfile::WriteValuePairsData( ostream & out, int writeComments, int mixedCase ) {
|
||||
std::string currSch = schemaName();
|
||||
int n = instances().InstanceCount();
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->WriteValuePairs( out, currSch, writeComments, mixedCase );
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->WriteValuePairs( out, currSch.c_str(), writeComments, mixedCase );
|
||||
}
|
||||
}
|
||||
|
||||
Severity
|
||||
STEPfile::AppendFile( istream * in, int useTechCor ) {
|
||||
Severity STEPfile::AppendFile( istream * in, int useTechCor ) {
|
||||
Severity rval = SEVERITY_NULL;
|
||||
char errbuf[BUFSIZ];
|
||||
|
||||
@@ -2393,8 +2383,7 @@ STEPfile::AppendFile( istream * in, int useTechCor ) {
|
||||
|
||||
|
||||
/******************************************************/
|
||||
Severity
|
||||
STEPfile::WriteWorkingFile( ostream & out, int clearError, int writeComments ) {
|
||||
Severity STEPfile::WriteWorkingFile( ostream & out, int clearError, int writeComments ) {
|
||||
SetFileType( WORKING_SESSION );
|
||||
if( clearError ) {
|
||||
_error.ClearErrorMsg();
|
||||
@@ -2416,8 +2405,7 @@ STEPfile::WriteWorkingFile( ostream & out, int clearError, int writeComments ) {
|
||||
}
|
||||
|
||||
/******************************************************/
|
||||
Severity
|
||||
STEPfile::WriteWorkingFile( const std::string filename, int clearError,
|
||||
Severity STEPfile::WriteWorkingFile( const std::string filename, int clearError,
|
||||
int writeComments ) {
|
||||
if( clearError ) {
|
||||
_error.ClearErrorMsg();
|
||||
@@ -2435,36 +2423,32 @@ STEPfile::WriteWorkingFile( const std::string filename, int clearError,
|
||||
|
||||
/***************************
|
||||
***************************/
|
||||
void
|
||||
STEPfile::WriteWorkingData( ostream & out, int writeComments ) {
|
||||
char currSch[BUFSIZ];
|
||||
currSch[0] = '\0';
|
||||
|
||||
schemaName( currSch );
|
||||
void STEPfile::WriteWorkingData( ostream & out, int writeComments ) {
|
||||
std::string currSch = schemaName();
|
||||
out << "DATA;\n";
|
||||
// SCLP23(Application_instance)* se;
|
||||
int n = instances().InstanceCount();
|
||||
|
||||
for( int i = 0; i < n; ++i ) {
|
||||
switch( instances().GetMgrNode( i )->CurrState() ) {
|
||||
case deleteSE:
|
||||
out << wsDelete;
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->
|
||||
STEPwrite( out, currSch, writeComments );
|
||||
STEPwrite( out, currSch.c_str(), writeComments );
|
||||
break;
|
||||
case completeSE:
|
||||
out << wsSaveComplete;
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->
|
||||
STEPwrite( out, currSch, writeComments );
|
||||
STEPwrite( out, currSch.c_str(), writeComments );
|
||||
break;
|
||||
case incompleteSE:
|
||||
out << wsSaveIncomplete;
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->
|
||||
STEPwrite( out, currSch, writeComments );
|
||||
STEPwrite( out, currSch.c_str(), writeComments );
|
||||
break;
|
||||
case newSE:
|
||||
out << wsNew;
|
||||
instances().GetMgrNode( i )->GetApplication_instance()->
|
||||
STEPwrite( out, currSch, writeComments );
|
||||
STEPwrite( out, currSch.c_str(), writeComments );
|
||||
break;
|
||||
case noStateSE:
|
||||
_error.AppendToUserMsg( "no state information for this node\n" );
|
||||
|
||||
@@ -143,8 +143,7 @@ class STEPfile
|
||||
|
||||
protected:
|
||||
//member functions
|
||||
char *schemaName( char * ); // returns and copies out schema name from
|
||||
// header instances
|
||||
const std::string schemaName(); // returns and copies out schema name from header instances
|
||||
//called by ReadExchangeFile
|
||||
istream* OpenInputFile (const std::string filename = "");
|
||||
void CloseInputFile(istream* in);
|
||||
|
||||
@@ -265,44 +265,49 @@ void STEPfile::SetFileIdIncrement() {
|
||||
( int )( ( ceil( ( ( instances().MaxFileId() + 99.0 ) / 1000.0 ) ) + 1.0 ) * 1000.0 );
|
||||
}
|
||||
|
||||
char * STEPfile::schemaName( char * schName )
|
||||
/*
|
||||
|
||||
/**
|
||||
* Returns the schema name from the file schema header section (or the 1st
|
||||
* one if more than one exists). Copies this value into schName. If there
|
||||
* is no header section or no value for file schema, NULL is returned and
|
||||
* schName is unset.
|
||||
*/
|
||||
{
|
||||
const std::string STEPfile::schemaName() {
|
||||
SdaiFile_schema * fs;
|
||||
std::string tmp;
|
||||
std::string schName;
|
||||
STEPnode * n;
|
||||
|
||||
|
||||
if( _headerInstances == NULL ) {
|
||||
return NULL;
|
||||
return schName;
|
||||
}
|
||||
fs = ( SdaiFile_schema * )_headerInstances->GetApplication_instance( "File_Schema" );
|
||||
if( fs == ENTITY_NULL ) {
|
||||
return NULL;
|
||||
return schName;
|
||||
}
|
||||
|
||||
n = ( STEPnode * )fs->schema_identifiers_()->GetHead();
|
||||
// (take the first one)
|
||||
if( n == NULL ) {
|
||||
return NULL;
|
||||
return schName;
|
||||
}
|
||||
n->STEPwrite( tmp );
|
||||
if( *tmp.c_str() == '\0' || *tmp.c_str() == '$' ) {
|
||||
return NULL;
|
||||
n->STEPwrite( schName );
|
||||
if( schName.empty() || schName[0] == '$' ) {
|
||||
schName.clear();
|
||||
return schName;
|
||||
} else if( schName[0] == '\0' ) {
|
||||
//probably never - it seems that putting null in std::string takes effort
|
||||
_error.AppendToUserMsg( "In STEPfile::schemaName: schName contains \\0 - it should be empty." );
|
||||
_error.GreaterSeverity( SEVERITY_WARNING );
|
||||
schName.clear();
|
||||
return schName;
|
||||
}
|
||||
// tmp.c_str() returns the string we want plus a beginning and ending
|
||||
// quote mark ('). We remove these below.
|
||||
strncpy( schName, tmp.c_str() + 1, BUFSIZ - 1 );
|
||||
// "+1" to remove beginning '.
|
||||
if( *( schName + strlen( schName ) - 1 ) == '\'' ) {
|
||||
// Remove trailing '. This condition checks that it wasn't removed
|
||||
// already. That may have happend if strncpy had truncated schName
|
||||
// (it were >= BUFSIZ).
|
||||
*( schName + strlen( schName ) - 1 ) = '\0';
|
||||
if( schName[ schName.length()-1 ] == '\'' ) {
|
||||
schName = schName.substr(1,schName.length()-2);
|
||||
} else {
|
||||
_error.AppendToUserMsg( "In STEPfile::schemaName: schName was truncated." );
|
||||
_error.GreaterSeverity( SEVERITY_WARNING );
|
||||
|
||||
schName = schName.substr(1,schName.length()-1);
|
||||
}
|
||||
return schName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user