RFR 8191516: OutputStream.write(byte[], int, int) could have fewer parameter bounds checks
https://bugs.openjdk.java.net/browse/JDK-8191516 http://cr.openjdk.java.net/~bpb/8191516/webrev.00/ Change OutputStream.write(byte[],int,int) to use the same three parameter bounds checks used by InputStream.read(byte[],int,int) instead of the five checks currently used. This change is covered by the existing test jdk/java/io/OutputStream/WriteParams.java. Thanks, Brian
On 20 Nov 2017, at 16:53, Brian Burkhalter <brian.burkhalter@oracle.com> wrote:
https://bugs.openjdk.java.net/browse/JDK-8191516 http://cr.openjdk.java.net/~bpb/8191516/webrev.00/
Change OutputStream.write(byte[],int,int) to use the same three parameter bounds checks used by InputStream.read(byte[],int,int) instead of the five checks currently used. This change is covered by the existing test jdk/java/io/OutputStream/WriteParams.java.
See also Objects.checkFromIndexSize if you wanna use that instead. Also the if len == 0 check is probably redundant, i doubt it makes any difference given the condition needs to be checked before entering the loop. Paul.
On Nov 20, 2017, at 6:32 PM, Paul Sandoz <paul.sandoz@oracle.com> wrote:
See also Objects.checkFromIndexSize if you wanna use that instead.
Also the if len == 0 check is probably redundant, i doubt it makes any difference given the condition needs to be checked before entering the loop.
Both good points. Updated accordingly: http://cr.openjdk.java.net/~bpb/8191516/webrev.01/. Thanks, Brian
On 21 Nov 2017, at 08:47, Brian Burkhalter <brian.burkhalter@oracle.com> wrote:
On Nov 20, 2017, at 6:32 PM, Paul Sandoz <paul.sandoz@oracle.com <mailto:paul.sandoz@oracle.com>> wrote:
See also Objects.checkFromIndexSize if you wanna use that instead.
Also the if len == 0 check is probably redundant, i doubt it makes any difference given the condition needs to be checked before entering the loop.
Both good points. Updated accordingly: http://cr.openjdk.java.net/~bpb/8191516/webrev.01/ <http://cr.openjdk.java.net/~bpb/8191516/webrev.01/>.
Looks good. How about updating the read method as well to use the bounds check method? (the len == 0 check makes sense there)? Paul.
On Nov 21, 2017, at 9:16 AM, Paul Sandoz <paul.sandoz@oracle.com> wrote:
Both good points. Updated accordingly: http://cr.openjdk.java.net/~bpb/8191516/webrev.01/.
Looks good. How about updating the read method as well to use the bounds check method? (the len == 0 check makes sense there)?
Probably might as well expand it a little to see where else similar changes might be made. Thanks, Brian
On Nov 21, 2017, at 9:21 AM, Brian Burkhalter <brian.burkhalter@oracle.com> wrote:
Looks good. How about updating the read method as well to use the bounds check method? (the len == 0 check makes sense there)?
Probably might as well expand it a little to see where else similar changes might be made.
Expanded to InputStream: http://cr.openjdk.java.net/~bpb/8191516/webrev.02/. The test java/io/InputStream/ReadParams verifies the changes to IS. Thanks, Brian
On 21 Nov 2017, at 12:30, Brian Burkhalter <brian.burkhalter@oracle.com> wrote:
On Nov 21, 2017, at 9:21 AM, Brian Burkhalter <brian.burkhalter@oracle.com <mailto:brian.burkhalter@oracle.com>> wrote:
Looks good. How about updating the read method as well to use the bounds check method? (the len == 0 check makes sense there)?
Probably might as well expand it a little to see where else similar changes might be made.
Expanded to InputStream: http://cr.openjdk.java.net/~bpb/8191516/webrev.02/ <http://cr.openjdk.java.net/~bpb/8191516/webrev.02/>. The test java/io/InputStream/ReadParams verifies the changes to IS.
+1 Paul.
participants (2)
-
Brian Burkhalter
-
Paul Sandoz