6999620: [parfait] potential buffer overruns in 2d and awt
authorbae
Mon, 24 Jan 2011 15:37:57 +0300
changeset 7952 5290e1887780
parent 7951 8479f9f404f8
child 7953 5b29f9801eac
child 8127 f97fecd0df7f
6999620: [parfait] potential buffer overruns in 2d and awt Reviewed-by: jgodinez, prr
jdk/src/windows/native/sun/java2d/d3d/D3DGraphicsDevice.cpp
jdk/src/windows/native/sun/windows/awt_Toolkit.cpp
--- a/jdk/src/windows/native/sun/java2d/d3d/D3DGraphicsDevice.cpp	Mon Jan 24 15:14:26 2011 +0300
+++ b/jdk/src/windows/native/sun/java2d/d3d/D3DGraphicsDevice.cpp	Mon Jan 24 15:37:57 2011 +0300
@@ -396,7 +396,7 @@
     UINT adapter;
     // EnumAdapterModes treats 555 and 565 formats as equivalents
     static D3DFORMAT formats[] =
-        { D3DFMT_X8R8G8B8, D3DFMT_R5G6B5 };
+      { D3DFMT_X8R8G8B8, D3DFMT_R5G6B5 };
 
     J2dTraceLn(J2D_TRACE_INFO, "D3DGD_enumDisplayModesNative");
 
@@ -404,7 +404,7 @@
     RETURN_IF_NULL(pd3d9 = pMgr->GetD3DObject());
     adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
 
-    for (formatNum = 0; formatNum < 3; formatNum++) {
+    for (formatNum = 0; formatNum < (sizeof formats)/(sizeof *formats); formatNum++) {
         modesCount = pd3d9->GetAdapterModeCount(adapter, formats[formatNum]);
         for (modeNum = 0; modeNum < modesCount; modeNum++) {
             if (SUCCEEDED(pd3d9->EnumAdapterModes(adapter, formats[formatNum],
--- a/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Mon Jan 24 15:14:26 2011 +0300
+++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Mon Jan 24 15:37:57 2011 +0300
@@ -2491,7 +2491,7 @@
     jint* colorsPtr = NULL;
     try {
         colorsPtr = (jint *)env->GetPrimitiveArrayCritical(colors, 0);
-        for (int i = 0; i < sizeof indexMap && i < colorLen; i++) {
+        for (int i = 0; i < (sizeof indexMap)/(sizeof *indexMap) && i < colorLen; i++) {
             colorsPtr[i] = DesktopColor2RGB(indexMap[i]);
         }
     } catch (...) {