« Return to Thread: "dir" crashing oactve 3.2.0/mingw32

"dir" crashing oactve 3.2.0/mingw32

by Benjamin Lindner :: Rate this Message:

Reply to Author | View in Thread

Hello,

there have been some reports that simply calling "dir" crashes octave
3.2.0/mingw32 on some windows platforms.
This has been tracked down to calls to strftime() failing with a "%T"
format specifier.

Mingw uses the strftime function provided by microsoft C runtime
library, and indeed msdn states that the following format specifiers are
supported: aAbBcdHIjmMpSUwWxXyYzZ

Mind that "T" is not supported, neither is "e".

Don't ask me why MS does not simply ignore other format specifiers, but
causes applications to crash. But changing "%T" to the equivalent
"%H:%M:%S" fixes the crashes in "dir".
Since "e" is neither supported, I propose to change it to "d" (with "%e"
being sprintf("%d",dayofmonth) and "%d" being sprintf("%02d",dayofmonth).

See the attached changeset.

It would be great to have this also fixed in 3.2.x

benjamin

# HG changeset patch
# User Benjamin Lindner <lindnerb@...>
# Date 1246121737 -7200
# Node ID 17dd42c0f54da8460aab457c7a631aa25a4cf1a0
# Parent  0dc089723162791456f0ae1c63dbe7e6790def8c
strftime format specifier fixes for MSCRT

diff -r 0dc089723162 -r 17dd42c0f54d scripts/ChangeLog
--- a/scripts/ChangeLog Fri Jun 26 16:20:02 2009 +0200
+++ b/scripts/ChangeLog Sat Jun 27 18:55:37 2009 +0200
@@ -1,3 +1,8 @@
+2009-06-27  Benjamin Lindner <lindnerb@...>
+
+ * image/iminfo.m, miscellaneous/dir.m: change unsupported strftime
+ format specifiers %T and %e on win32.
+
 2009-06-25  Ben Abbott <bpabbott@...>
 
  * plot/gnuplot_drawnow.m: Apply feature 'wxt_has_size'.
diff -r 0dc089723162 -r 17dd42c0f54d scripts/image/imfinfo.m
--- a/scripts/image/imfinfo.m Fri Jun 26 16:20:02 2009 +0200
+++ b/scripts/image/imfinfo.m Sat Jun 27 18:55:37 2009 +0200
@@ -124,7 +124,7 @@
       error ("imfinfo: error reading '%s': %s", fn, msg);
     endif
 
-    time_stamp = strftime ("%e-%b-%Y %H:%M:%S", localtime (statinfo.mtime));
+    time_stamp = strftime ("%d-%b-%Y %H:%M:%S", localtime (statinfo.mtime));
   
     info = __magick_finfo__ (fn);
     info.FileModDate = time_stamp;
diff -r 0dc089723162 -r 17dd42c0f54d scripts/miscellaneous/dir.m
--- a/scripts/miscellaneous/dir.m Fri Jun 26 16:20:02 2009 +0200
+++ b/scripts/miscellaneous/dir.m Sat Jun 27 18:55:37 2009 +0200
@@ -114,7 +114,7 @@
   fn = cstrcat (fn, ext);
   info(i,1).name = fn;
   lt = localtime (st.mtime);
-  info(i,1).date = strftime ("%d-%b-%Y %T", lt);
+  info(i,1).date = strftime ("%d-%b-%Y %H:%M:%S", lt);
   info(i,1).bytes = st.size;
   info(i,1).isdir = S_ISDIR (st.mode);
   info(i,1).datenum = datenum (lt.year + 1900, lt.mon, lt.mday,
diff -r 0dc089723162 -r 17dd42c0f54d src/ChangeLog
--- a/src/ChangeLog Fri Jun 26 16:20:02 2009 +0200
+++ b/src/ChangeLog Sat Jun 27 18:55:37 2009 +0200
@@ -1,3 +1,8 @@
+2009-06-27  Benjamin Lindner <lindnerb@...>
+
+ * load-save.cc: change unsupported strftime format specifiers %T and %e
+ on win32
+
 2009-06-26  John W. Eaton  <jwe@...>
 
  * load-path.cc (Faddpath): Preserve order of prepended elements.
diff -r 0dc089723162 -r 17dd42c0f54d src/load-save.cc
--- a/src/load-save.cc Fri Jun 26 16:20:02 2009 +0200
+++ b/src/load-save.cc Sat Jun 27 18:55:37 2009 +0200
@@ -1183,7 +1183,7 @@
  memset (headertext, ' ', 124);
  // ISO 8601 format date
  strftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave "
-  OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt);
+  OCTAVE_VERSION ", %Y-%m-%d %H:%M:%S UTC", &bdt);
 
  // The first pair of bytes give the version of the MAT file
  // format.  The second pair of bytes form a magic number which

 « Return to Thread: "dir" crashing oactve 3.2.0/mingw32