Skip to content

Commit

Permalink
COMP: fixed cppcheck warnings about unneeded c_str() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
seanm authored and N-Dekker committed Jan 7, 2025
1 parent 0a1d475 commit 113c332
Show file tree
Hide file tree
Showing 27 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Examples/IO/IOPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ main(int argc, char * argv[])
#endif
}
myenv += std::string(argv[3]);
itksys::SystemTools::PutEnv(myenv.c_str());
itksys::SystemTools::PutEnv(myenv);

itk::ObjectFactoryBase::ReHash();
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/src/itkObjectFactoryBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ ObjectFactoryBase::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

os << indent << "Factory DLL path: " << m_LibraryPath.c_str() << '\n';
os << indent << "Factory DLL path: " << m_LibraryPath << '\n';
os << indent << "Factory description: " << this->GetDescription() << std::endl;

auto num = static_cast<int>(m_OverrideMap->size());
Expand All @@ -614,8 +614,8 @@ ObjectFactoryBase::PrintSelf(std::ostream & os, Indent indent) const
indent = indent.GetNextIndent();
for (auto & i : *m_OverrideMap)
{
os << indent << "Class : " << i.first.c_str() << '\n';
os << indent << "Overridden with: " << i.second.m_OverrideWithName.c_str() << std::endl;
os << indent << "Class : " << i.first << '\n';
os << indent << "Overridden with: " << i.second.m_OverrideWithName << std::endl;
os << indent << "Enable flag: " << i.second.m_EnabledFlag << std::endl;
os << indent << "Create object: " << i.second.m_CreateObject << std::endl;
os << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/TestKernel/src/itkTestDriver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ AddEntriesBeforeLibraryPath(const ArgumentsList & args)
libpath += ITK_TEST_DRIVER_PATH_SEP;
libpath += oldenv;
}
itksys::SystemTools::PutEnv(libpath.c_str());
itksys::SystemTools::PutEnv(libpath);
// on some 64 bit systems, LD_LIBRARY_PATH_64 is used before
// LD_LIBRARY_PATH if it is set. It can lead the test to load
// the system library instead of the expected one, so this
Expand All @@ -121,7 +121,7 @@ AddEntriesBeforeLibraryPath(const ArgumentsList & args)
libpath64 += ITK_TEST_DRIVER_PATH_SEP;
libpath64 += oldenv64;
}
itksys::SystemTools::PutEnv(libpath64.c_str());
itksys::SystemTools::PutEnv(libpath64);
}

++i;
Expand All @@ -145,7 +145,7 @@ AddEntriesBeforeEnvironment(const ArgumentsList & args)
env += ITK_TEST_DRIVER_PATH_SEP;
env += oldenv;
}
itksys::SystemTools::PutEnv(env.c_str());
itksys::SystemTools::PutEnv(env);

i += 2;
}
Expand All @@ -168,7 +168,7 @@ AddEntriesBeforeEnvironmentWithSeparator(const ArgumentsList & args)
env += args[i + 2];
env += oldenv;
}
itksys::SystemTools::PutEnv(env.c_str());
itksys::SystemTools::PutEnv(env);

i += 3;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/TestKernel/src/itkTestDriverInclude.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ ProcessArguments(int * argc, ArgumentStringType * argv, ProcessedOutputType * pr
// set the environment which will be read by the subprocess
std::string threadEnv = "ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=";
threadEnv += (*argv)[i + 1];
itksys::SystemTools::PutEnv(threadEnv.c_str());
itksys::SystemTools::PutEnv(threadEnv);
// and set the number of threads locally for the comparison
itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads(std::stoi((*argv)[i + 1]));
*argv += 2;
Expand Down
4 changes: 2 additions & 2 deletions Modules/IO/BMP/src/itkBMPImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ BMPImageIO::ReadImageInformation()
// error checking
if ((infoSize != 40) && (infoSize != 12))
{
itkExceptionMacro("Unknown file type! " << m_FileName.c_str() << " is not a Windows BMP file!");
itkExceptionMacro("Unknown file type! " << m_FileName << " is not a Windows BMP file!");
}

// there are two different types of BMP files
Expand Down Expand Up @@ -429,7 +429,7 @@ BMPImageIO::ReadImageInformation()
// error checking
if ((infoSize != 40) && (infoSize != 12))
{
itkExceptionMacro("Unknown file type! " << m_FileName.c_str() << " is not a Windows BMP file!");
itkExceptionMacro("Unknown file type! " << m_FileName << " is not a Windows BMP file!");
}

// there are two different types of BMP files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ itkHDF5ImageIOStreamingReadWriteTest(int argc, char * argv[])
{
prefix = *++argv;
--argc;
itksys::SystemTools::ChangeDirectory(prefix.c_str());
itksys::SystemTools::ChangeDirectory(prefix);
}
itk::ObjectFactoryBase::RegisterFactory(itk::HDF5ImageIOFactory::New());

Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/HDF5/test/itkHDF5ImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ itkHDF5ImageIOTest(int argc, char * argv[])
{
prefix = *++argv;
--argc;
itksys::SystemTools::ChangeDirectory(prefix.c_str());
itksys::SystemTools::ChangeDirectory(prefix);
}
itk::ObjectFactoryBase::RegisterFactory(itk::HDF5ImageIOFactory::New());

Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/IPL/src/itkIPLCommonImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ IPLCommonImageIO::ReadImageInformation()
// TODO -- use std::string instead of C strings
char imageMask[IOCommon::ITK_MAXPATHLEN + 1];
char imagePath[IOCommon::ITK_MAXPATHLEN + 1];
const std::string _imagePath = itksys::SystemTools::CollapseFullPath(FileNameToRead.c_str());
const std::string _imagePath = itksys::SystemTools::CollapseFullPath(FileNameToRead);

FileNameToRead = _imagePath;

Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/ImageBase/include/itkImageFileWriter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ImageFileWriter<TInputImage>::Write()
ImageFileWriterException e(__FILE__, __LINE__);
std::ostringstream msg;
const std::list<LightObject::Pointer> allobjects = ObjectFactoryBase::CreateAllInstance("itkImageIOBase");
msg << " Could not create IO object for writing file " << m_FileName.c_str() << std::endl;
msg << " Could not create IO object for writing file " << m_FileName << std::endl;
if (!allobjects.empty())
{
msg << " Tried to create one of the following:" << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions Modules/IO/ImageBase/src/itkArchetypeSeriesFileNames.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ ArchetypeSeriesFileNames::Scan()
std::string unixArchetype = m_Archetype;
itksys::SystemTools::ConvertToUnixSlashes(unixArchetype);

if (itksys::SystemTools::FileIsDirectory(unixArchetype.c_str()))
if (itksys::SystemTools::FileIsDirectory(unixArchetype))
{
return;
}

// Parse the fileNameName and fileNamePath
const std::string origFileName = itksys::SystemTools::GetFilenameName(unixArchetype.c_str());
std::string fileNamePath = itksys::SystemTools::GetFilenamePath(unixArchetype.c_str());
const std::string origFileName = itksys::SystemTools::GetFilenameName(unixArchetype);
std::string fileNamePath = itksys::SystemTools::GetFilenamePath(unixArchetype);
std::string pathPrefix;

// "Clean" the filename by escaping any special characters with backslashes.
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/ImageBase/src/itkImageIOBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ ImageIOBase::OpenFileForWriting(std::ofstream & outputStream, const std::string
// opening a nonexistent file for reading + writing is not allowed on some platforms
if (!itksys::SystemTools::FileExists(filename.c_str()))
{
itksys::SystemTools::Touch(filename.c_str(), true);
itksys::SystemTools::Touch(filename, true);
// don't worry about failure here, errors should be detected later when the file
// is "actually" opened, unless there is a race condition
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ RegularExpressionSeriesFileNames::GetFileNames()

// Process all files in the directory
itksys::Directory fileDir;
if (!fileDir.Load(m_Directory.c_str()))
if (!fileDir.Load(m_Directory))
{
itkExceptionMacro("Directory " << m_Directory.c_str() << " cannot be read!");
itkExceptionMacro("Directory " << m_Directory << " cannot be read!");
}

std::vector<std::pair<std::string, std::string>> sortedBySubMatch;
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/ImageBase/src/itkStreamingImageIOBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ StreamingImageIOBase::GetActualNumberOfSplitsForWriting(unsigned int nu

// need to remove the file incase the file doesn't match our
// current header/meta data information
if (!itksys::SystemTools::RemoveFile(m_FileName.c_str()))
if (!itksys::SystemTools::RemoveFile(m_FileName))
{
itkExceptionMacro("Unable to remove file for streaming: " << m_FileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ActualTest(std::string inputFileName,

// We remove the output file
// NOTE ALEX: should we check it exists first?
itksys::SystemTools::RemoveFile(outputFileName.c_str());
itksys::SystemTools::RemoveFile(outputFileName);

using PixelType = unsigned char;
using ImageType = itk::Image<PixelType, 3>;
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/JPEG2000/src/itkJPEG2000ImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ JPEG2000ImageIO::Write(const void * buffer)
opj_cparameters_t parameters;
opj_set_default_encoder_parameters(&parameters);

const std::string extension = itksys::SystemTools::GetFilenameLastExtension(this->m_FileName.c_str());
const std::string extension = itksys::SystemTools::GetFilenameLastExtension(this->m_FileName);
if (extension == ".j2k")
{
parameters.cod_format = static_cast<int>(JPEG2000ImageIOInternal::DecodingFormatEnum::J2K_CFMT);
Expand Down
16 changes: 8 additions & 8 deletions Modules/IO/MINC/src/itkMINCImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ MINCImageIO::ReadImageInformation()
if (miopen_volume(m_FileName.c_str(), MI2_OPEN_READ, &m_MINCPImpl->m_Volume) < 0)
{
// Error opening the volume
itkExceptionMacro("Could not open file \"" << m_FileName.c_str() << "\".");
itkExceptionMacro("Could not open file \"" << m_FileName << "\".");
}

// find out how many dimensions are there regularly sampled
Expand Down Expand Up @@ -1059,7 +1059,7 @@ MINCImageIO::WriteImageInformation()
if (ExposeMetaData<std::string>(thisDic, "dimension_order", dimension_order))
{
// the format should be ((+|-)(X|Y|Z|V|T))*
// std::cout<<"Restoring original dimension order:"<<dimension_order.c_str()<<std::endl;
// std::cout<<"Restoring original dimension order:"<<dimension_order<<std::endl;
if (dimension_order.length() == (minc_dimensions * 2))
{
dimorder_good = true;
Expand All @@ -1073,7 +1073,7 @@ MINCImageIO::WriteImageInformation()
case 'V':
if (nComp <= 1)
{
itkDebugMacro("Dimension order is incorrect " << dimension_order.c_str());
itkDebugMacro("Dimension order is incorrect " << dimension_order);
dimorder_good = false;
}
else
Expand All @@ -1085,7 +1085,7 @@ MINCImageIO::WriteImageInformation()
case 'T':
if (nComp <= 1)
{
itkDebugMacro("Dimension order is incorrect " << dimension_order.c_str());
itkDebugMacro("Dimension order is incorrect " << dimension_order);
dimorder_good = false;
}
else
Expand All @@ -1106,7 +1106,7 @@ MINCImageIO::WriteImageInformation()
j = m_MINCPImpl->m_NDims - 1 - ((nComp > 1 ? 1 : 0) + 2);
break;
default:
itkDebugMacro("Dimension order is incorrect " << dimension_order.c_str());
itkDebugMacro("Dimension order is incorrect " << dimension_order);
dimorder_good = false;
j = 0;
break;
Expand Down Expand Up @@ -1140,7 +1140,7 @@ MINCImageIO::WriteImageInformation()
}
else
{
itkDebugMacro("Dimension order is incorrect " << dimension_order.c_str());
itkDebugMacro("Dimension order is incorrect " << dimension_order);
}
}

Expand Down Expand Up @@ -1196,14 +1196,14 @@ MINCImageIO::WriteImageInformation()
// Error opening the volume
MINCIOFreeTmpDimHandle(minc_dimensions, m_MINCPImpl->m_MincApparentDims);
mifree_volume_props(hprops);
itkExceptionMacro("Could not open file \"" << m_FileName.c_str() << "\".");
itkExceptionMacro("Could not open file \"" << m_FileName << "\".");
}

if (micreate_volume_image(m_MINCPImpl->m_Volume) < 0)
{
// Error opening the volume
mifree_volume_props(hprops);
itkExceptionMacro("Could not create image in file \"" << m_FileName.c_str() << "\".");
itkExceptionMacro("Could not create image in file \"" << m_FileName << "\".");
}

if (miset_apparent_dimension_order(m_MINCPImpl->m_Volume, minc_dimensions, m_MINCPImpl->m_MincApparentDims) < 0)
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/MINC/test/itkMINCImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ itkMINCImageIOTest(int argc, char * argv[])
{
prefix = *++argv;
--argc;
itksys::SystemTools::ChangeDirectory(prefix.c_str());
itksys::SystemTools::ChangeDirectory(prefix);
}

itk::ObjectFactoryBase::RegisterFactory(itk::MINCImageIOFactory::New(),
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/MeshBase/include/itkMeshFileReader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ MeshFileReader<TOutputMesh, ConvertPointPixelTraits, ConvertCellPixelTraits>::Ge
if (m_MeshIO.IsNull())
{
std::ostringstream msg;
msg << " Could not create IO object for file " << m_FileName.c_str() << std::endl;
msg << " Could not create IO object for file " << m_FileName << std::endl;
if (!m_ExceptionMessage.empty())
{
msg << m_ExceptionMessage;
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/MeshBase/include/itkMeshFileWriter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MeshFileWriter<TInputMesh>::Write()
{
MeshFileWriterException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << " Could not create IO object for file " << m_FileName.c_str() << std::endl
msg << " Could not create IO object for file " << m_FileName << std::endl
<< " Tried to create one of the following:" << std::endl;
{
for (auto & allobject : ObjectFactoryBase::CreateAllInstance("itkMeshIOBase"))
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/Meta/src/itkMetaImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ MetaImageIO::GetActualNumberOfSplitsForWriting(unsigned int numberOfReq

// need to remove the file incase the file doesn't match our
// current header/meta data information
if (!itksys::SystemTools::RemoveFile(m_FileName.c_str()))
if (!itksys::SystemTools::RemoveFile(m_FileName))
{
itkExceptionMacro("Unable to remove file for streaming: " << m_FileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ itkPolygonGroupSpatialObjectXMLFileTest(int argc, char * argv[])
std::cerr << "Error Reading file" << std::endl;
return EXIT_FAILURE;
}
itksys::SystemTools::RemoveFile(xmlfilename.c_str());
itksys::SystemTools::RemoveFile(xmlfilename);

return testPolygonGroupEquivalence(PolygonGroup, PGroupFromFile);
}
4 changes: 2 additions & 2 deletions Modules/IO/Stimulate/src/itkStimulateImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ StimulateImageIO::InternalReadImageInformation(std::ifstream & file)
const std::string datafilenamePath = ::itksys::SystemTools::GetFilenamePath(datafilename);
if (datafilenamePath.empty())
{
const std::string fileNamePath = ::itksys::SystemTools::GetFilenamePath(m_FileName.c_str());
const std::string fileNamePath = ::itksys::SystemTools::GetFilenamePath(m_FileName);
m_DataFileName = fileNamePath + "/" + datafilename;
}
else
Expand Down Expand Up @@ -566,7 +566,7 @@ StimulateImageIO::Write(const void * buffer)
// determine datafile given the spr filename
m_DataFileName = m_FileName;
m_DataFileName.replace(m_DataFileName.length() - 3, 3, "sdt");
file << "\nstimFileName: " << m_DataFileName.c_str();
file << "\nstimFileName: " << m_DataFileName;

// Last carrier return:
file << '\n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int
secondTest(const std::string & outputDirectory)
{
std::filebuf fb;
fb.open((outputDirectory + "IllegalTransform.txt").c_str(), std::ios::out);
fb.open((outputDirectory + "IllegalTransform.txt"), std::ios::out);
std::ostream os(&fb);
os << "#Insight Transform File V1.0" << std::endl
<< "#Transform 0" << std::endl
Expand Down
10 changes: 5 additions & 5 deletions Modules/IO/XML/include/itkFileTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FileTools::CreateDirectory(const std::string & dir)
}

// do nothing if it already exists
if (dir.empty() || "." == dir || itksys::SystemTools::FileIsDirectory(dir.c_str()))
if (dir.empty() || "." == dir || itksys::SystemTools::FileIsDirectory(dir))
{
return;
}
Expand All @@ -71,7 +71,7 @@ FileTools::CreateDirectory(const std::string & dir)
itksys::SystemTools::MakeDirectory(dir.c_str());

// check successful or not
if (!itksys::SystemTools::FileIsDirectory(dir.c_str()))
if (!itksys::SystemTools::FileIsDirectory(dir))
{
ExceptionObject eo(__FILE__, __LINE__, "directory cannot be created");
throw eo;
Expand All @@ -82,7 +82,7 @@ FileTools::CreateDirectory(const std::string & dir)
inline void
FileTools::CreateFile(const std::string & fn)
{
if (fn.empty() || itksys::SystemTools::FileIsDirectory(fn.c_str()))
if (fn.empty() || itksys::SystemTools::FileIsDirectory(fn))
{
ExceptionObject eo(__FILE__, __LINE__, "file cannot be created");
throw eo;
Expand All @@ -95,11 +95,11 @@ FileTools::CreateFile(const std::string & fn)
}

// make sure the directory exists
const std::string dir = itksys::SystemTools::GetFilenamePath(fn.c_str());
const std::string dir = itksys::SystemTools::GetFilenamePath(fn);
FileTools::CreateDirectory(dir);

// create the file
itksys::SystemTools::Touch(fn.c_str(), true);
itksys::SystemTools::Touch(fn, true);

// check successful or not
if (!itksys::SystemTools::FileExists(fn.c_str(), true))
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/XML/src/itkXMLFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ XMLReaderBase::parse()
}

// Default stream parser just reads a block at a time.
const std::streamsize filesize = itksys::SystemTools::FileLength(m_Filename.c_str());
const std::streamsize filesize = itksys::SystemTools::FileLength(m_Filename);

const auto buffer = make_unique_for_overwrite<char[]>(filesize);

Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/XML/test/itkDOMTest8.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ itkDOMTest8(int argc, char * argv[])
// create the file in the directory
std::string fn(argv[1]);
fn.append(argv[2]);
itk::FileTools::CreateFile(fn.c_str());
itk::FileTools::CreateFile(fn);

// the testings are successful if reached here
}
Expand Down
Loading

0 comments on commit 113c332

Please sign in to comment.