Replace unsafe c from/to string functions#
VTK 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 member functions can be provided with strings that use the std::format style format in addition to the printf style:
void vtkControlPointsItem::SetLabelFormat(const char* formatArg)void vtkTimerLog::FormatAndMarkEvent(const char* formatArg, T&&... args)void vtkAngleRepresentation::SetLabelFormat(const char* formatArg)void vtkBiDimensionalRepresentation::SetLabelFormat(const char* formatArg)void vtkDistanceRepresentation::SetLabelFormat(const char* formatArg)void vtkLineRepresentation::SetDistanceAnnotationFormat(const char* formatArg)void vtkResliceCursorRepresentation::SetThicknessLabelFormat(const char* formatArg)void vtkSliderRepresentation::SetLabelFormat(const char* formatArg)void vtkImageReader2::SetFilePattern(const char* formatArg)void vtkImageWriter::SetFilePattern(const char* formatArg)void vtkVolumeReader::SetFilePattern(const char* formatArg)void vtkPDataSetWriter::SetFilePattern(const char* formatArg)void vtkPExodusIIReader::SetFilePattern(const char* formatArg)void vtkAxisActor::SetLabelFormat(const char* formatArg)void vtkAxisActor2D::SetLabelFormat(const char* formatArg)void vtkCubeAxesActor::SetXLabelFormat(const char* formatArg)void vtkCubeAxesActor::SetYLabelFormat(const char* formatArg)void vtkCubeAxesActor::SetZLabelFormat(const char* formatArg)void vtkCubeAxesActor2D::SetLabelFormat(const char* formatArg)void vtkLeaderActor2D::SetLabelFormat(const char* formatArg)void vtkParallelCoordinatesActor::SetLabelFormat(const char* formatArg)void vtkPolarAxesActor::SetPolarLabelFormat(const char* formatArg)void vtkScalarBarActor::SetLabelFormat(const char* formatArg)void vtkXYPlotActor::SetXLabelFormat(const char* formatArg)void vtkXYPlotActor::SetYLabelFormat(const char* formatArg)void vtkLabeledDataMapper::SetLabelFormat(const char* formatArg)void vtkFastLabeledDataMapper::SetLabelFormat(const char* formatArg)void vtkDateToNumeric::SetDateFormat(const char* formatArg)void vtkPlot::SetTooltipLabelFormat(const vtkStdString& labelFormat)