On 19/08/2010 21:52, Sergey Khorev wrote:
F1rst!  :-)

Pros: All Windows specific code.
Cons: Can't do anything clever with an invalid format string.

Should be ok with mingw32.

Wow, so quick :)
I think you've done it right by installing the handler once and for
all. For users of ancient compilers I suggest to add something like:
#if (defined(__MINGW32__) || defined (__CYGWIN32__))&&
__MSVCRT_VERSION__>= 0x800 \
   || defined(_MSC_VER)&&  _MSC_VER>= 1400

Works for me. Checked with VC6 which does not have the invalid param handler. I tidied it up for potential ambiguity and reworked the patch - see attached. Using macros for the function calls removes the needs for duplicating the complex conditional or introducing another symbol for later conditional compilation. I commend to the house.

TTFN

Mike
--
Words are not food, though sometimes we must eat them.

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/os_win32.c b/src/os_win32.c
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -1615,6 +1615,34 @@
     return TRUE;
 }
 
+#if ((defined(__MINGW32__) || defined (__CYGWIN32__)) && \
+        __MSVCRT_VERSION__ >= 0x800) || (defined(_MSC_VER) && _MSC_VER >= 1400)
+/*
+ * Bad parameter handler.
+ *
+ * Certain MS CRT functions will intentionally crash when passed invalid
+ * parameters to highlight possible security holes.  Setting this function as
+ * the bad parameter handler will prevent the crash.
+ *
+ * In debug builds the parameters contain CRT information that might help track
+ * down the source of a problem, but in non-debug builds the arguments are all
+ * NULL/0.  Debug builds will also produce assert dialogs from the CRT, it is
+ * worth allowing these to make debugging of issues easier.
+ */
+static void
+bad_param_handler(const wchar_t* expression,
+    const wchar_t* function,
+    const wchar_t* file,
+    unsigned int line,
+    uintptr_t pReserved)
+{
+}
+#define SET_INVALID_PARAM_HANDLER() \
+                      ((void)_set_invalid_parameter_handler(bad_param_handler))
+#else
+#define SET_INVALID_PARAM_HANDLER() ((void)0)
+#endif
+
 #ifdef FEAT_GUI_W32
 
 /*
@@ -1627,6 +1655,9 @@
     extern int _fmode;
 #endif
 
+    /* Silently handle invalid parameters to CRT functions */
+    SET_INVALID_PARAM_HANDLER();
+
     /* Let critical errors result in a failure, not in a dialog box.  Required
      * for the timestamp test to work on removed floppies. */
     SetErrorMode(SEM_FAILCRITICALERRORS);
@@ -2103,6 +2134,9 @@
     extern int _fmode;
 #endif
 
+    /* Silently handle invalid parameters to CRT functions */
+    SET_INVALID_PARAM_HANDLER();
+
     /* Let critical errors result in a failure, not in a dialog box.  Required
      * for the timestamp test to work on removed floppies. */
     SetErrorMode(SEM_FAILCRITICALERRORS);

Raspunde prin e-mail lui