Replace unsafe c from/to string functions
ParaView has been using a set of either unsafe or slow C/C++ functions to convert numbers to string or vice versa. The exhaustive list of functions is given below. And all of them have been replaced with safer alternatives/faster alternatives provided by scnlib, fmt, and fast_float libraries and exposed though the vtk:: namespace.
C/C++ has the following functions to convert one/many char or string to a number.
- atof, atoi, atol, atoll,
- std::stof, std::stod, std::stold, std::stoi, std::stol, std::stoll, std::stoul, std::stoull
- std::strtof, std::strtod, std::strtold, std::strtol, std::strtoll/_strtoi64, std::strtoul, std::strtoull
- sscanf, sscanf_s, vsscanf, vsscanf_s
- std::from_chars (This is slow because it does not use fast_float under the hood)
These functions should be replaced by:
- vtk::from_chars, vtk::scan_int, vtk::scan_value, if one number needs to be converted
- vtk::scan, if one/many numbers need to be converted (optionally with a specific format)
C/C++ has the following functions to scan one/many numbers from a stdin/file.
- scanf, scanf_s, vscanf, vscanf_s,
- fscanf, fscanf_s, vfscanf, vfscanf_s,
These functions should be replaced by:
- vtk::scan_value, if one number needs to be converted
- vtk::input, vtk::scan, if one/many numbers need to be converted (optionally with a specific format)
C/C++ has the following functions to convert one/many numbers to a char or string.
- itoa/_itoa, ltoa/_ltoa, lltoa/_i64toa, ultoa/_ultoa, ulltoa/_ulltoa/_ui64toa
- sprintf, sprintf_s, vsprintf, vsprintf_s,
- snprintf, snprintf_s, vsnprintf, vsnprintf_s,
- strftime
- std::to_chars, std::to_string
These functions should be replaced by:
- vtk::to_chars or vtk::to_string, if one number needs to be converted
- vtk::format, vtk::format_to, or vtk::format_to_n, if one/many numbers need to be converted with a specific format
C/C++ has the following functions to print one/many numbers to stdout/file.
- printf, printf_s, vprintf, vprintf_s,
- fprintf, fprintf_s, vfprintf, vfprintf_s,
These functions should be replaced by:
- vtk::print, vtk::println
It should also be noted that the following functions (including subclasses that use them) need to be provided with strings that use the std::format style format instead of the printf one:
void vtkAnnotateGlobalDataFilter::SetFormat(const char* formatArg)
void vtkCGNSWriter::SetFileNameSuffix(const char* suffix)
void vtkContext2DScalarBarActor::SetRangeLabelFormat(const char* formatArg)
void vtkCSVWriter::SetFileNameSuffix(const char* suffix)
void vtkFileSeriesWriter::SetFileNameSuffix(const char* suffix)
void vtkParallelSerialWriter::SetFileNameSuffix(const char* suffix)
void vtkParticlePipeline::SetFilename(const char* filename)
void SceneImageWriterImageSeries::SetSuffixFormat(const char* suffix)
void vtkStringList::AddFormattedString(const char* EventString, T&&... args)
Finally, the following string properties now use the std::format style format instead of the printf one:
ScalarBarActor.LabelFormat
ScalarBarActor.RangeLabelFormat
TexturedScalarBarActor.LabelFormat
TexturedScalarBarActor.RangeLabelFormat
RulerSourceRepresentation.LabelFormat
ProtractorRepresentation.LabelFormat
ExodusIIReaderCore.FilePattern
PNGWriter.FilePattern
TIFFWriter.FilePattern
JPEGWriter.FilePattern
PolarAxesRepresentation.PolarLabelFormat
DateToNumeric.DateFormat
XYChartViewBase.TooltipLabelFormat
JPEG.SuffixFormat
PNG.SuffixFormat
TIFF.SuffixFormat
BPM.SuffixFormat
FileSeriesWriter.FileNameSuffix
FileSeriesWriterComposite.FileNameSuffix
ParallelFileSeriesWriter.FileNameSuffix
ParallelSerialWriter.FileNameSuffix
CGNSWriter.FileNameSuffix
CSVWriter.FileNameSuffix
This MR resolves part of #18589.