]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make a char[30] variable into a std::string.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 19 Sep 2019 03:42:47 +0000 (21:42 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 19 Sep 2019 03:42:47 +0000 (21:42 -0600)
This avoids the potential for buffer overflows.

include/deal.II/algorithms/timestep_control.h
source/algorithms/timestep_control.cc

index 1f0ce0340b00143fb6fa0cce2212a60cd1d9ae7c..b82f65e524586ff7f9d77e0f098c50bf0567a4b1 100644 (file)
@@ -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;
index a54a0a1599303186b9016672bb3939212b6748ef..10dff0e1e806d996e6720becb5afe86b4c94d782 100644 (file)
@@ -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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.