Re: Updated fix for 687461,C stack overflow quetly quits |

Ray Johnston <[email protected]> Tue, 31 Aug 2004 10:42:27 -0700
Newsgroups gmane.comp.printing.ghostscript.patches
Organization Artifex Software Inc.
Message-ID <[email protected]>
Alex,

I agree that GCC on Windows is a low priority.

Please go ahead and commit.

Regards,
Ray
___________________________________________________________________

Igor V. Melichev wrote:

> Ray,
> 
> IMO this patch to be approved. Thank you.
> 
> Igor.
> 
> ----- Original Message ----- 
> From: "Igor V. Melichev" <[email protected]>
> To: "Alex Cherepanov" <[email protected]>; "gs-code-review" <[email protected]>
> Sent: Monday, August 30, 2004 5:13 PM
> Subject: Re: [gs-code-review] Updated fix for 687461,C stack overflow quetly quis 
> 
> 
> 
>>Alex,
>>
>>The patch looks fine with me,
>>and IMO GCC/Windows isn't so important.
>>Note I'm not an official reviewer for bug bounty.
>>
>>Igor.
>>
>>----- Original Message ----- 
>>From: "Alex Cherepanov" <[email protected]>
>>To: "gs-code-review" <[email protected]>
>>Sent: Saturday, August 28, 2004 12:36 AM
>>Subject: [gs-code-review] Updated fix for 687461,C stack overflow quetly quis 
>>
>>
>>
>>>Trap C stack overflow exception on Borland C and MSVC. Without the
>>>trap the application silently terminates when C stack overflows.
>>>
>>>[DETAILS]
>>>Watcom C 1.2 doesn't need the trap. It is also the only compiler tested 
>>>that converts trailing recursion to iteration. GCC 3.2 on Windows still 
>>>generates programs that fail silently but I don't know how to fix this. 
>>>GCC 2.95 on Linux reports the stack overflow.
>>>
>>
>>
>>--------------------------------------------------------------------------------
>>
>>
>>
>>>Index: gs/src/dwmain.c
>>>===================================================================
>>>RCS file: /cvs/ghostscript/gs/src/dwmain.c,v
>>>retrieving revision 1.19
>>>diff -b -u -r1.19 dwmain.c
>>>--- gs/src/dwmain.c 19 Aug 2004 19:33:09 -0000 1.19
>>>+++ gs/src/dwmain.c 27 Aug 2004 20:18:29 -0000
>>>@@ -17,8 +17,7 @@
>>> /* $Id: dwmain.c,v 1.19 2004/08/19 19:33:09 stefan Exp $ */
>>> /* Ghostscript DLL loader for Windows */
>>> 
>>>-#define STRICT
>>>-#include <windows.h>
>>>+#include "windows_.h"
>>> #include <shellapi.h>
>>> #include <stdio.h>
>>> #include <string.h>
>>>@@ -328,12 +327,21 @@
>>>     nargv[2] = ddpi;
>>>     memcpy(&nargv[3], &argv[1], argc * sizeof(char *));
>>> 
>>>+#if defined(_MSC_VER) || defined(__BORLANDC__)
>>>+    __try {
>>>+#endif
>>>     code = gsdll.init_with_args(instance, nargc, nargv);
>>>     if (code == 0)
>>>  code = gsdll.run_string(instance, start_string, 0, &exit_code);
>>>     code1 = gsdll.exit(instance);
>>>     if (code == 0 || (code == e_Quit && code1 != 0))
>>>  code = code1;
>>>+#if defined(_MSC_VER) || defined(__BORLANDC__)
>>>+    } __except(exception_code() == EXCEPTION_STACK_OVERFLOW) {
>>>+        code = e_Fatal;
>>>+        text_puts(tw, "*** C stack overflow. Quiting...\n");
>>>+    }
>>>+#endif
>>> 
>>>     gsdll.delete_instance(instance);
>>> 
>>>Index: gs/src/dwmainc.c
>>>===================================================================
>>>RCS file: /cvs/ghostscript/gs/src/dwmainc.c,v
>>>retrieving revision 1.22
>>>diff -b -u -r1.22 dwmainc.c
>>>--- gs/src/dwmainc.c 19 Aug 2004 21:52:20 -0000 1.22
>>>+++ gs/src/dwmainc.c 27 Aug 2004 20:18:30 -0000
>>>@@ -17,7 +17,7 @@
>>> /* $Id: dwmainc.c,v 1.22 2004/08/19 21:52:20 ghostgum Exp $ */
>>> /* dwmainc.c */
>>> 
>>>-#include <windows.h>
>>>+#include "windows_.h"
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>> #include <io.h>
>>>@@ -415,12 +415,21 @@
>>>     nargv[2] = ddpi;
>>>     memcpy(&nargv[3], &argv[1], argc * sizeof(char *));
>>> 
>>>+#if defined(_MSC_VER) || defined(__BORLANDC__)
>>>+    __try {
>>>+#endif
>>>     code = gsdll.init_with_args(instance, nargc, nargv);
>>>     if (code == 0)
>>>  code = gsdll.run_string(instance, start_string, 0, &exit_code);
>>>     code1 = gsdll.exit(instance);
>>>     if (code == 0 || (code == e_Quit && code1 != 0))
>>>  code = code1;
>>>+#if defined(_MSC_VER) || defined(__BORLANDC__)
>>>+    } __except(exception_code() == EXCEPTION_STACK_OVERFLOW) {
>>>+        code = e_Fatal;
>>>+        fprintf(stderr, "*** C stack overflow. Quiting...\n");
>>>+    }
>>>+#endif
>>> 
>>>     gsdll.delete_instance(instance);
>>> 
>>>Index: gs/src/windows_.h
>>>===================================================================
>>>RCS file: /cvs/ghostscript/gs/src/windows_.h,v
>>>retrieving revision 1.6
>>>diff -b -u -r1.6 windows_.h
>>>--- gs/src/windows_.h 8 Apr 2004 16:18:25 -0000 1.6
>>>+++ gs/src/windows_.h 27 Aug 2004 20:18:30 -0000
>>>@@ -46,4 +46,8 @@
>>> #  define _fstrtok(str, set) strtok(str, set)
>>> #endif
>>> 
>>>+#if defined(__BORLANDC__)
>>>+#  define exception_code() __exception_code  
>>>+#endif
>>>+
>>> #endif /* windows__INCLUDED */
>>>Index: gs/src/winint.mak
>>>===================================================================
>>>RCS file: /cvs/ghostscript/gs/src/winint.mak,v
>>>retrieving revision 1.21
>>>diff -b -u -r1.21 winint.mak
>>>--- gs/src/winint.mak 30 Jan 2004 08:40:57 -0000 1.21
>>>+++ gs/src/winint.mak 27 Aug 2004 20:18:30 -0000
>>>@@ -139,7 +139,7 @@
>>> 
>>> OBJCNO=$(PSOBJ)dwmainc.obj $(PSOBJ)dwnodllc.obj $(GLOBJ)dwimg.obj $(DWTRACE) $(GLOBJ)dwreg.obj
>>> 
>>>-$(PSOBJ)dwmainc.obj: $(PSSRC)dwmainc.c $(AK) $(fcntl__h) $(unistd__h) \
>>>+$(PSOBJ)dwmainc.obj: $(PSSRC)dwmainc.c $(AK) $(windows__h) $(fcntl__h) $(unistd__h) \
>>>   $(iapi_h) $(vdtrace_h) $(gdevdsp_h) $(dwdll_h) $(dwimg_h) $(dwtrace_h)
>>>  $(PSCCWIN) $(COMPILE_FOR_CONSOLE_EXE) $(PSO_)dwmainc.obj $(C_) $(PSSRC)dwmainc.c
>>> 
>>>@@ -169,7 +169,7 @@
>>>  $(gscdefs_h) $(stdpre_h) $(gsdll_h) $(vdtrace_h)
>>>  $(GLCPP) $(COMPILE_FOR_EXE) $(GLO_)dwtrace.obj $(C_) $(GLSRC)dwtrace.c
>>> 
>>>-$(PSOBJ)dwmain.obj: $(PSSRC)dwmain.c $(AK)\
>>>+$(PSOBJ)dwmain.obj: $(PSSRC)dwmain.c $(AK)  $(windows__h) \
>>>  $(iapi_h) $(vdtrace_h) $(dwmain_h) $(dwdll_h) $(dwtext_h) $(dwimg_h) $(dwtrace_h) \
>>>  $(dwreg_h) $(gdevdsp_h)
>>>  $(PSCCWIN) $(COMPILE_FOR_EXE) $(PSO_)dwmain.obj $(C_) $(PSSRC)dwmain.c
>>>
>>
>>
>>--------------------------------------------------------------------------------
>>
>>
>>
>>>_______________________________________________
>>>gs-code-review mailing list
>>>[email protected]
>>>http://www.ghostscript.com/mailman/listinfo/gs-code-review
>>>
> 
> 
> 

-- 
Ray Johnston
Director of Engineering                          Tel: (714) 484-0376
Artifex Software Inc.                            Fax: (714) 220-1022
______________________________________________________________________