From 480bc40c6a85ccf61457d472625e4958b1481ff6 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 18 Sep 2019 21:42:47 -0600 Subject: [PATCH] Make a char[30] variable into a std::string. This avoids the potential for buffer overflows. --- include/deal.II/algorithms/timestep_control.h | 12 ++++++------ source/algorithms/timestep_control.cc | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/deal.II/algorithms/timestep_control.h b/include/deal.II/algorithms/timestep_control.h index 1f0ce0340b..b82f65e524 100644 --- a/include/deal.II/algorithms/timestep_control.h +++ b/include/deal.II/algorithms/timestep_control.h @@ -190,12 +190,12 @@ namespace Algorithms * Set the output name template. */ void - file_name_format(const char *); + file_name_format(const std::string &format); /** * Return the output name template. */ - const char * + const std::string & file_name_format(); private: @@ -265,7 +265,7 @@ namespace Algorithms /** * Output file name template. */ - char format[30]; + std::string format; }; @@ -360,13 +360,13 @@ namespace Algorithms inline void - TimestepControl::file_name_format(const char *fmt) + TimestepControl::file_name_format(const std::string &fmt) { - strcpy(format, fmt); + format = fmt; } - inline const char * + inline const std::string & TimestepControl::file_name_format() { return format; diff --git a/source/algorithms/timestep_control.cc b/source/algorithms/timestep_control.cc index a54a0a1599..10dff0e1e8 100644 --- a/source/algorithms/timestep_control.cc +++ b/source/algorithms/timestep_control.cc @@ -39,9 +39,9 @@ TimestepControl::TimestepControl(double start, , step_val(start_step) , print_step(print_step) , next_print_val(print_step > 0. ? start_val + print_step : start_val - 1.) + , format("T.%06.3f") { now_val = start_val; - strcpy(format, "T.%06.3f"); // avoid compiler warning (void)min_step_val; -- 2.39.5