[OpenJDK 2D-Dev] RFR: JDK-8204211: windows : handle potential C++ exception in GDIRenderer -was : RE: java2d coding using SAFE_SIZE_ARRAY_ALLOC / safe_Malloc
Baesken, Matthias
matthias.baesken at sap.com
Fri Jun 1 12:18:16 UTC 2018
Hi Thomas , using the const-reference sounds like a good idea ( I just copied from other locations in the source code where (almost?) always std::bad_alloc& (non-const) is caught .
For example :
alloc.h 170 } catch (std::bad_alloc&) { \
177 } catch (std::bad_alloc&) { \
200 } catch (std::bad_alloc&) { \
206 } catch (std::bad_alloc&) { \
awt_InputTextInfor.cpp 223 } catch (std::bad_alloc&) {
247 } catch (std::bad_alloc&) {
317 } catch (std::bad_alloc&) {
372 } catch (std::bad_alloc&) {
407 } catch (std::bad_alloc&) {
awt_DnDDT.cpp 203 } catch (std::bad_alloc&) {
264 } catch (std::bad_alloc&) {
305 } catch (std::bad_alloc&) {
366 } catch (std::bad_alloc&) {
582 } catch (std::bad_alloc&) {
635 } catch (std::bad_alloc&) {
653 } catch (std::bad_alloc&) {
698 } catch (std::bad_alloc&) {
739 } catch (std::bad_alloc&) {
awt_Desktop.cpp 148 } catch (std::bad_alloc&) {
WPrinterJob.cpp 166 } catch (std::bad_alloc&) {
345 } catch (std::bad_alloc&) {
425 } catch (std::bad_alloc&) {
488 } catch (std::bad_alloc&) {
631 } catch (std::bad_alloc&) {
709 } catch (std::bad_alloc&) {
awt_ole.h 158 } catch (std::bad_alloc&) {\
awt_DesktopProperties.cpp 125 catch (std::bad_alloc&) {
269 catch (std::bad_alloc&) {
647 catch (std::bad_alloc&) {
664 catch (std::bad_alloc&) {
689 catch (std::bad_alloc&) {
awt_PrintDialog.cpp 225 } catch (std::bad_alloc&) {
awt_DataTransferer.cpp 310 } catch (std::bad_alloc&) {
724 } catch (std::bad_alloc &) {
792 } catch (std::bad_alloc &) {
awt_MenuItem.cpp 328 } catch (std::bad_alloc&) {
348 } catch (std::bad_alloc&) {
524 } catch (std::bad_alloc&) {
ShellFolder2.cpp 1410 } catch (std::bad_alloc&) {
1435 } catch (std::bad_alloc&) {
...
Best regards, Matthias
> -----Original Message-----
> From: Thomas Stüfe [mailto:thomas.stuefe at gmail.com]
> Sent: Freitag, 1. Juni 2018 12:02
> To: Baesken, Matthias <matthias.baesken at sap.com>
> Cc: 2d-dev <2d-dev at openjdk.java.net>; Langer, Christoph
> <christoph.langer at sap.com>
> Subject: Re: RFR: JDK-8204211: windows : handle potential C++ exception in
> GDIRenderer -was : RE: [OpenJDK 2D-Dev] java2d coding using
> SAFE_SIZE_ARRAY_ALLOC / safe_Malloc
>
> Hi Matthias,
>
> Please consider catching all exceptions, not just std::alloc:
>
> } catch (...) { return NULL; }
>
> and doing it at the exit extern "C" function, not somewhere
> internally. Regardless of which exceptions get thrown around below you
> and by whom, you are safe that way.
>
> However, if you want to keep your patch as it is, please catch at
> least as const reference:
>
> } catch (const std::bad_alloc&) {}
>
> Fine otherwise. I do not need another webrev.
>
> Best Regards, Thomas
>
>
>
>
>
> On Fri, Jun 1, 2018 at 10:39 AM, Baesken, Matthias
> <matthias.baesken at sap.com> wrote:
> > Hi Thomas , thanks for the feedback.
> > I created a bug and change for the excpetion handling in GDIRenderer.cpp
> .
> > Please review .
> >
> > Thanks, Matthias
> >
> > Bug:
> >
> > https://bugs.openjdk.java.net/browse/JDK-8204211
> >
> > JDK-8204211: windows : handle potential C++ exception in GDIRenderer
> >
> >
> > Change :
> >
> >
> > http://cr.openjdk.java.net/~mbaesken/webrevs/8204211/
> >
> >
> >
> >
> >> -----Original Message-----
> >> From: Thomas Stüfe [mailto:thomas.stuefe at gmail.com]
> >> Sent: Mittwoch, 30. Mai 2018 17:37
> >> To: Baesken, Matthias <matthias.baesken at sap.com>
> >> Cc: 2d-dev <2d-dev at openjdk.java.net>
> >> Subject: Re: [OpenJDK 2D-Dev] java2d coding using
> >> SAFE_SIZE_ARRAY_ALLOC / safe_Malloc
> >>
> >> Letting c++ exceptions escape from extern "C" functions is UB and may
> >> (and probably will) crash the process. This should be fixed. Approach
> >> taken by JDK-8039394 is fine (I would probably catch every C++
> >> exception with catch(...), not just bad_alloc, just to be safe).
> >>
> >> Best Regards, Thomas
> >>
> >> On Wed, May 30, 2018 at 5:08 PM, Baesken, Matthias
> >> <matthias.baesken at sap.com> wrote:
> >> > Hello , there is still some java2d coding where
> SAFE_SIZE_ARRAY_ALLOC /
> >> > safe_Malloc is used and the (potentially occurring) exception is not
> >> > handled .
> >> >
> >> >
> >> >
> >> > This leads to CL warnings (when enabled ) like
> >> >
> >> >
> >> >
> >> > " function assumed not to throw an exception but does ; The function is
> >> > extern "C" and /EHc was specified"
> >> >
> >> >
> >> >
> >> > Example :
> >> >
> >> >
> >> >
> >> >
> java.desktop/windows/native/libawt/java2d/windows/GDIRenderer.cpp
> >> >
> >> >
> >> >
> >> > static POINT *TransformPoly()
> >> >
> >> > …..
> >> >
> >> > if (outpoints > POLYTEMPSIZE) {
> >> >
> >> > pPoints = (POINT *) SAFE_SIZE_ARRAY_ALLOC(safe_Malloc,
> >> > sizeof(POINT), outpoints);
> >> >
> >> > }
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > Should we add exception handling here ?
> >> >
> >> >
> >> >
> >> > Similar fixes were done in the change 8039394: Compiler warnings
> about
> >> C++
> >> > exceptions in windows printing code
> >> >
> >> >
> >> >
> >> > https://bugs.openjdk.java.net/browse/JDK-8039394
> >> >
> >> > http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/823387e2bf42
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > Best regards, Matthias
> >> >
> >> >
> >> >
> >> >
More information about the 2d-dev
mailing list