8204211: windows : handle potential C++ exception in GDIRenderer
authormbaesken
Mon, 04 Jun 2018 16:11:21 +0200
changeset 50484 f8c15a2f2ae9
parent 50483 10b8e57899b3
child 50485 e2acd1ba1ee5
8204211: windows : handle potential C++ exception in GDIRenderer Reviewed-by: clanger, prr, serb
make/lib/Awt2dLibraries.gmk
src/java.desktop/windows/native/libawt/java2d/windows/GDIRenderer.cpp
src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp
--- a/make/lib/Awt2dLibraries.gmk	Tue Jun 05 14:42:21 2018 -0700
+++ b/make/lib/Awt2dLibraries.gmk	Mon Jun 04 16:11:21 2018 +0200
@@ -224,7 +224,7 @@
         format-nonliteral parentheses, \
     DISABLED_WARNINGS_clang := logical-op-parentheses extern-initializer, \
     DISABLED_WARNINGS_solstudio := E_DECLARATION_IN_CODE, \
-    DISABLED_WARNINGS_microsoft := 4297 4244 4267 4996, \
+    DISABLED_WARNINGS_microsoft := 4244 4267 4996, \
     ASFLAGS := $(LIBAWT_ASFLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) $(call SET_SHARED_LIBRARY_ORIGIN), \
     LDFLAGS_macosx := -L$(INSTALL_LIBRARIES_HERE), \
--- a/src/java.desktop/windows/native/libawt/java2d/windows/GDIRenderer.cpp	Tue Jun 05 14:42:21 2018 -0700
+++ b/src/java.desktop/windows/native/libawt/java2d/windows/GDIRenderer.cpp	Mon Jun 04 16:11:21 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -85,7 +85,11 @@
         *pNpoints = outpoints;
     }
     if (outpoints > POLYTEMPSIZE) {
-        pPoints = (POINT *) SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, sizeof(POINT), outpoints);
+        try {
+            pPoints = (POINT *) SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, sizeof(POINT), outpoints);
+        } catch (const std::bad_alloc&) {
+            return NULL;
+        }
     }
     BOOL isempty = fixend;
     for (int i = 0; i < npoints; i++) {
--- a/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp	Tue Jun 05 14:42:21 2018 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp	Mon Jun 04 16:11:21 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -873,7 +873,13 @@
       int numSizes = ::DeviceCapabilities(printerName, printerPort,
                                           DC_PAPERS, NULL, NULL);
       if (numSizes > 0) {
-          LPTSTR papers = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, numSizes, sizeof(WORD));
+          LPTSTR papers;
+          try {
+              papers = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, numSizes, sizeof(WORD));
+          } catch (const std::bad_alloc&) {
+              papers = NULL;
+          }
+
           if (papers != NULL &&
               ::DeviceCapabilities(printerName, printerPort,
                                    DC_PAPERS, papers, NULL) != -1) {