4343#include < stdio.h>
4444#endif
4545
46- #ifdef _MSC_VER
46+ #if defined(_MSC_VER) && !defined(__MINGW32__)
47+ #define USE_WINDOWS_SEH
4748#include < Windows.h>
4849#include < excpt.h>
4950#endif
@@ -304,13 +305,27 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * /*context*
304305}
305306#endif
306307
307- #ifdef _MSC_VER
308+ #ifdef USE_WINDOWS_SEH
308309/*
309310 * Any evaluation of the information about the exception needs to be done here!
310311 */
311312static int filterException (int code, PEXCEPTION_POINTERS ex)
312313{
313- // TODO we should try to extract some information here.
314+ // TODO we should try to extract more information here
315+ // - address, read/write
316+ switch (ex->ExceptionRecord ->ExceptionCode ) {
317+ case EXCEPTION_ACCESS_VIOLATION:
318+ fprintf (stderr, " Internal error (EXCEPTION_ACCESS_VIOLATION)\n " );
319+ break ;
320+ case EXCEPTION_IN_PAGE_ERROR:
321+ fprintf (stderr, " Internal error (EXCEPTION_IN_PAGE_ERROR)\n " );
322+ break ;
323+ default :
324+ fprintf (stderr, " Internal error (%d)\n " ,
325+ code);
326+ break ;
327+ }
328+ fprintf (stderr, " Please report this to the cppcheck developers!\n " );
314329 return EXCEPTION_EXECUTE_HANDLER;
315330}
316331#endif
@@ -322,20 +337,15 @@ static int filterException(int code, PEXCEPTION_POINTERS ex)
322337 */
323338int CppCheckExecutor::check_wrapper (CppCheck& cppCheck, int argc, const char * const argv[])
324339{
325- #ifdef _MSC_VER
326- /* not yet finished
327- __try {
328- */
329- return check_internal (cppCheck, argc, argv);
330- /*
331- }
332- __except(filterException(GetExceptionCode(), GetExceptionInformation())) {
333- // reporting to stdout may not be helpful within a GUI application..
334- fprintf(stderr, "Internal error\n");
335- fprintf(stderr, "Please report this to the cppcheck developers!\n");
340+ #ifdef USE_WINDOWS_SEH
341+ __try {
342+ return check_internal (cppCheck, argc, argv);
343+ } __except (filterException (GetExceptionCode (), GetExceptionInformation ())) {
344+ // reporting to stdout may not be helpful within a GUI application..
345+ fprintf (stderr, " Internal error\n " );
346+ fprintf (stderr, " Please report this to the cppcheck developers!\n " );
336347 return -1 ;
337348 }
338- */
339349#elif defined(USE_UNIX_SIGNAL_HANDLING)
340350 struct sigaction act;
341351 memset (&act, 0 , sizeof (act));
0 commit comments