Commit b7621616 authored by Sean McBride's avatar Sean McBride

Fixed bug #17677: use a thread_local to avoid returning a dangling pointer

- Fixes clang -Wreturn-stack-address warning.
- Added std::string versions of the methods
parent ee0c9688
Pipeline #148033 running with stage
......@@ -715,6 +715,11 @@ int vtkLSDynaReader::CanReadFile( const char* fname )
return result > 0; // -1 and 0 are both problems, 1 indicates success.
}
void vtkLSDynaReader::SetDatabaseDirectory( const std::string& f )
{
this->SetDatabaseDirectory(f.c_str());
}
void vtkLSDynaReader::SetDatabaseDirectory( const char* f )
{
vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting DatabaseDirectory to " << f );
......@@ -739,16 +744,30 @@ void vtkLSDynaReader::SetDatabaseDirectory( const char* f )
}
}
#if defined(VTK_LEGACY_REMOVE)
std::string vtkLSDynaReader::GetDatabaseDirectory()
{
return this->P->Fam.GetDatabaseDirectory();
}
#else
const char* vtkLSDynaReader::GetDatabaseDirectory()
{
return this->P->Fam.GetDatabaseDirectory().c_str();
static thread_local std::string surrogate;
surrogate = this->GetDatabaseDirectory();
return surrogate.c_str();
}
#endif
int vtkLSDynaReader::IsDatabaseValid()
{
return this->P->FileIsValid;
}
void vtkLSDynaReader::SetFileName( const std::string& f )
{
this->SetFileName(f.c_str());
}
void vtkLSDynaReader::SetFileName( const char* f )
{
std::string dbDir = vtksys::SystemTools::GetFilenamePath( f );
......@@ -789,13 +808,20 @@ void vtkLSDynaReader::SetFileName( const char* f )
}
}
#if defined(VTK_LEGACY_REMOVE)
std::string vtkLSDynaReader::GetFileName()
{
std::string filename = this->P->Fam.GetDatabaseDirectory() + "/d3plot";
return filename;
}
#else
const char* vtkLSDynaReader::GetFileName()
{
// This is completely thread UNsafe. But what to do?
static std::string filenameSurrogate;
filenameSurrogate = this->P->Fam.GetDatabaseDirectory() + "/d3plot";
return filenameSurrogate.c_str();
static thread_local std::string surrogate;
surrogate = this->P->Fam.GetDatabaseDirectory() + "/d3plot";
return surrogate.c_str();
}
#endif
char* vtkLSDynaReader::GetTitle()
{
......
......@@ -190,8 +190,13 @@ public:
* Get/Set the directory containing the LS-Dyna database and determine
* whether it is valid.
*/
virtual void SetDatabaseDirectory( const std::string& );
virtual void SetDatabaseDirectory( const char* );
const char* GetDatabaseDirectory();
#ifdef VTK_LEGACY_REMOVE
std::string GetDatabaseDirectory();
#else
VTK_LEGACY(const char* GetDatabaseDirectory());
#endif
int IsDatabaseValid();
//@}
......@@ -202,8 +207,13 @@ public:
* filename you choose is irrelevant -- only the directory name is used.
* This is done in order to accommodate ParaView.
*/
virtual void SetFileName( const std::string& );
virtual void SetFileName( const char* );
const char* GetFileName();
#ifdef VTK_LEGACY_REMOVE
std::string GetFileName();
#else
VTK_LEGACY(const char* GetFileName());
#endif
//@}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment