7107013: sun.jvm.hotspot.runtime.Bytes.swapLong conversion to long mishandled
authordsamersoff
Wed, 16 Nov 2016 14:11:30 +0300
changeset 42571 a4eea8e17d0b
parent 42570 5a4f3339b5d9
child 42572 faf8f5152129
7107013: sun.jvm.hotspot.runtime.Bytes.swapLong conversion to long mishandled Summary: Cast to long to avoid truncation in swapLong() Reviewed-by: dsamersoff Contributed-by: Sharath Ballal <sharath.ballal@oracle.com>
hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Bytes.java
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Bytes.java	Tue Nov 15 19:39:51 2016 -0500
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Bytes.java	Wed Nov 16 14:11:30 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, 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
@@ -51,7 +51,7 @@
     if (!swap)
       return x;
 
-    return (swapShort((short) x) << 16) | (swapShort((short) (x >> 16)) & 0xFFFF);
+    return ((int)swapShort((short) x) << 16) | (swapShort((short) (x >> 16)) & 0xFFFF);
   }
 
   /** Should only swap if the hardware's underlying byte order is
@@ -60,6 +60,6 @@
     if (!swap)
       return x;
 
-    return (swapInt((int) x) << 32) | (swapInt((int) (x >> 32)) & 0xFFFFFFFF);
+    return ((long)swapInt((int) x) << 32) | (swapInt((int) (x >> 32)) & 0xFFFFFFFF);
   }
 }