--- octave-4.4.1-orig/liboctave/system/oct-env.cc	2018-08-09 18:20:32 +0000
+++ octave-4.4.1/liboctave/system/oct-env.cc	2018-08-25 12:12:59 +0000
@@ -72,7 +72,7 @@
       // Etc.
       do_get_user_name ();
 
-      do_get_host_name ();
+      // It is not safe to call do_get_host_name () within DllMain on Win32 systems!
     }
 
     env *env::instance = nullptr;
@@ -520,7 +520,7 @@
         {
           char hostname[1024];
 
-          int status = octave_gethostname_wrapper (hostname, 1023);
+          int status = octave_gethostname_wrapper (hostname, sizeof(hostname) - 1);
 
           host_name = (status < 0) ? "unknown" : hostname;
         }
--- octave-4.4.1-orig/libinterp/corefcn/load-save.cc	2018-08-09 18:20:32 +0000
+++ octave-4.4.1/libinterp/corefcn/load-save.cc	2018-09-29 09:25:10 +0000
@@ -91,23 +91,74 @@
 #  include "zfstream.h"
 #endif
 
-// Write octave-workspace file if Octave crashes or is killed by a signal.
-static bool Vcrash_dumps_octave_core = true;
+namespace {
+    class LoadSaveIntVars {
+    public:
+        bool crash_dumps_octave_core() const
+            {
+                return Vcrash_dumps_octave_core;
+            }
 
-// The maximum amount of memory (in kilobytes) that we will attempt to
-// write to the Octave core file.
-static double Voctave_core_file_limit = -1.0;
+        octave_value crash_dumps_octave_core(const octave_value_list& args, int nargout)
+            {  
+                return SET_INTERNAL_VARIABLE (crash_dumps_octave_core);
+            }
 
-// The name of the Octave core file.
-static std::string Voctave_core_file_name = "octave-workspace";
+        double octave_core_file_limit() const
+            {
+                return Voctave_core_file_limit;
+            }
 
-// The default output format.  May be one of "binary", "text",
-// "mat-binary", or "hdf5".
-static std::string Vsave_default_options = "-text";
+        octave_value octave_core_file_limit(const octave_value_list& args, int nargout)
+            {  
+                return SET_INTERNAL_VARIABLE (octave_core_file_limit);
+            }
 
-// The output format for Octave core files.
-static std::string Voctave_core_file_options = "-binary";
+        const std::string& octave_core_file_name() const
+            {
+                return Voctave_core_file_name;
+            }
+
+        octave_value octave_core_file_name(const octave_value_list& args, int nargout)
+            {
+                return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name);
+            }
+
+        const std::string& save_default_options() const
+            {
+                return Vsave_default_options;
+            }
+
+        octave_value save_default_options(const octave_value_list& args, int nargout)
+            {
+                return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (save_default_options);
+            }
+
+        const std::string& octave_core_file_options() const
+            {
+                return Voctave_core_file_options;
+            }
+  
+        octave_value octave_core_file_options(const octave_value_list& args, int nargout)
+            {
+                return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options);
+            }
+
+        const std::string& save_header_format_string() const
+            {
+                init_save_header_format_string();
+  
+                return Vsave_header_format_string;
+            }
+
+        octave_value save_header_format_string(const octave_value_list& args, int nargout)
+            {
+                init_save_header_format_string();
 
+                return SET_INTERNAL_VARIABLE (save_header_format_string);
+            }
+
+    private:
 static std::string
 default_save_header_format (void)
 {
@@ -120,10 +171,37 @@
     + '>';
 }
 
+        void init_save_header_format_string() const
+            {
+                if (b_init_save_header_format) {
+                    Vsave_header_format_string = default_save_header_format ();
+                    b_init_save_header_format = false;
+                }
+            }
+        // Write octave-workspace file if Octave crashes or is killed by a signal.
+        bool Vcrash_dumps_octave_core = true;
+
+        // The maximum amount of memory (in kilobytes) that we will attempt to
+        // write to the Octave core file.
+        double Voctave_core_file_limit = -1.0;
+
+        // The name of the Octave core file.
+        std::string Voctave_core_file_name = "octave-workspace";
+
+        // The default output format.  May be one of "binary", "text",
+        // "mat-binary", or "hdf5".
+        std::string Vsave_default_options = "-text";
+
+        // The output format for Octave core files.
+        std::string Voctave_core_file_options = "-binary";
+
 // The format string for the comment line at the top of text-format
 // save files.  Passed to strftime.  Should begin with '#' and contain
 // no newline characters.
-static std::string Vsave_header_format_string = default_save_header_format ();
+        mutable std::string Vsave_header_format_string;
+        mutable bool b_init_save_header_format = true;
+    } load_save_vars;
+}
 
 OCTAVE_NORETURN static
 void
@@ -1229,7 +1307,7 @@
       {
         octave::sys::localtime now;
 
-        std::string comment_string = now.strftime (Vsave_header_format_string);
+        std::string comment_string = now.strftime (load_save_vars.save_header_format_string());
 
         if (! comment_string.empty ())
           {
@@ -1363,8 +1441,8 @@
 
           // FIXME: maybe we should try to throw out the largest first...
 
-          if (Voctave_core_file_limit < 0
-              || save_mem_size + val_size < Voctave_core_file_limit)
+          if (load_save_vars.octave_core_file_limit() < 0
+              || save_mem_size + val_size < load_save_vars.octave_core_file_limit())
             {
               save_mem_size += val_size;
 
@@ -1379,11 +1457,11 @@
 void
 dump_octave_core (void)
 {
-  if (Vcrash_dumps_octave_core)
+  if (load_save_vars.crash_dumps_octave_core())
     {
       // FIXME: should choose better filename?
 
-      const char *fname = Voctave_core_file_name.c_str ();
+      const char *fname = load_save_vars.octave_core_file_name().c_str ();
 
       message (nullptr, "attempting to save variables to '%s'...", fname);
 
@@ -1395,7 +1473,7 @@
 
       bool use_zlib = false;
 
-      parse_save_options (Voctave_core_file_options, format, append,
+      parse_save_options (load_save_vars.octave_core_file_options(), format, append,
                           save_as_floats, use_zlib);
 
       std::ios::openmode mode = std::ios::out;
@@ -1619,7 +1697,7 @@
   bool use_zlib = false;
 
   // get default options
-  parse_save_options (Vsave_default_options, format, append, save_as_floats,
+  parse_save_options (load_save_vars.save_default_options(), format, append, save_as_floats,
                       use_zlib);
 
   // override from command line
@@ -1766,7 +1844,7 @@
 @seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}
 @end deftypefn */)
 {
-  return SET_INTERNAL_VARIABLE (crash_dumps_octave_core);
+  return load_save_vars.crash_dumps_octave_core(args, nargout);
 }
 
 DEFUN (save_default_options, args, nargout,
@@ -1786,7 +1864,7 @@
 @seealso{save, save_header_format_string, save_precision}
 @end deftypefn */)
 {
-  return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (save_default_options);
+  return load_save_vars.save_default_options(args, nargout);
 }
 
 DEFUN (octave_core_file_limit, args, nargout,
@@ -1812,7 +1890,7 @@
 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}
 @end deftypefn */)
 {
-  return SET_INTERNAL_VARIABLE (octave_core_file_limit);
+  return load_save_vars.octave_core_file_limit(args, nargout);
 }
 
 DEFUN (octave_core_file_name, args, nargout,
@@ -1831,7 +1909,7 @@
 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}
 @end deftypefn */)
 {
-  return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name);
+  return load_save_vars.octave_core_file_name(args, nargout);
 }
 
 DEFUN (octave_core_file_options, args, nargout,
@@ -1852,7 +1930,7 @@
 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}
 @end deftypefn */)
 {
-  return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options);
+  return load_save_vars.octave_core_file_options(args, nargout);
 }
 
 DEFUN (save_header_format_string, args, nargout,
@@ -1880,5 +1958,5 @@
 @seealso{strftime, save_default_options}
 @end deftypefn */)
 {
-  return SET_INTERNAL_VARIABLE (save_header_format_string);
+  return load_save_vars.save_header_format_string(args, nargout);
 }
--- octave-4.4.1-orig/libinterp/corefcn/oct-hist.cc	2018-08-09 18:20:32 +0000
+++ octave-4.4.1/libinterp/corefcn/oct-hist.cc	2018-09-29 09:24:59 +0000
@@ -104,6 +104,24 @@
   return size;
 }
 
+namespace {
+    class HistIntVars {
+    public:
+        const std::string& history_timestamp_format_string() const
+            {
+                init_history_timestamp_format_string();
+                
+                return Vhistory_timestamp_format_string;
+            }
+        
+        octave_value history_timestamp_format_string(const octave_value_list& args, int nargout)
+            {
+                init_history_timestamp_format_string();
+                
+                return SET_INTERNAL_VARIABLE (history_timestamp_format_string);
+            }
+
+    private:
 static std::string
 default_history_timestamp_format (void)
 {
@@ -115,10 +133,22 @@
     + '>';
 }
 
+
+        void init_history_timestamp_format_string() const
+            {
+                if (b_init_history_timestamp_format_string)
+                {
+                    Vhistory_timestamp_format_string = default_history_timestamp_format ();
+                    b_init_history_timestamp_format_string = false;
+                }
+            }
+        
 // The format of the timestamp marker written to the history file when
 // Octave exits.
-static std::string Vhistory_timestamp_format_string
-  = default_history_timestamp_format ();
+        mutable std::string Vhistory_timestamp_format_string;
+        mutable bool b_init_history_timestamp_format_string = true;
+    } hist_vars;
+}
 
 // Display, save, or load history.  Stolen and modified from bash.
 //
@@ -544,7 +574,7 @@
 {
   octave::sys::localtime now;
 
-  std::string timestamp = now.strftime (Vhistory_timestamp_format_string);
+  std::string timestamp = now.strftime (hist_vars.history_timestamp_format_string());
 
   if (! timestamp.empty ())
     if (octave::command_history::add (timestamp))
@@ -822,7 +852,7 @@
 @seealso{strftime, history_file, history_size, history_save}
 @end deftypefn */)
 {
-  return SET_INTERNAL_VARIABLE (history_timestamp_format_string);
+    return hist_vars.history_timestamp_format_string(args, nargout);
 }
 
 DEFUN (history_save, args, nargout,
