mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-13 01:13:10 +00:00
8055032: Improve numerical parsing in java.net and sun.net
Reviewed-by: alanb
This commit is contained in:
parent
72e770ad77
commit
579e48fd60
@ -368,7 +368,7 @@ public class CookieManager extends CookieHandler
|
||||
int val = -1;
|
||||
while (i > 0) {
|
||||
try {
|
||||
val = Integer.parseInt(lst.substring(0, i));
|
||||
val = Integer.parseInt(lst, 0, i, 10);
|
||||
if (val == port) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3250,7 +3250,7 @@ public final class URI
|
||||
if (q > p) {
|
||||
checkChars(p, q, L_DIGIT, H_DIGIT, "port number");
|
||||
try {
|
||||
port = Integer.parseInt(substring(p, q));
|
||||
port = Integer.parseInt(input, p, q, 10);
|
||||
} catch (NumberFormatException x) {
|
||||
fail("Malformed port number", p);
|
||||
}
|
||||
@ -3271,7 +3271,7 @@ public final class URI
|
||||
int p = start;
|
||||
int q = scan(p, n, L_DIGIT, H_DIGIT);
|
||||
if (q <= p) return q;
|
||||
if (Integer.parseInt(substring(p, q)) > 255) return p;
|
||||
if (Integer.parseInt(input, p, q, 10) > 255) return p;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ public class URLDecoder {
|
||||
|
||||
while ( ((i+2) < numChars) &&
|
||||
(c=='%')) {
|
||||
int v = Integer.parseInt(s.substring(i+1,i+3),16);
|
||||
int v = Integer.parseInt(s, i + 1, i + 3, 16);
|
||||
if (v < 0)
|
||||
throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value");
|
||||
bytes[pos++] = (byte) v;
|
||||
|
||||
@ -196,7 +196,8 @@ public abstract class URLStreamHandler {
|
||||
++ind ;
|
||||
// port can be null according to RFC2396
|
||||
if (nhost.length() > (ind + 1)) {
|
||||
port = Integer.parseInt(nhost.substring(ind+1));
|
||||
port = Integer.parseInt(nhost, ind + 1,
|
||||
nhost.length(), 10);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
@ -213,7 +214,8 @@ public abstract class URLStreamHandler {
|
||||
if (ind >= 0) {
|
||||
// port can be null according to RFC2396
|
||||
if (host.length() > (ind + 1)) {
|
||||
port = Integer.parseInt(host.substring(ind + 1));
|
||||
port = Integer.parseInt(host, ind + 1,
|
||||
host.length(), 10);
|
||||
}
|
||||
host = host.substring(0, ind);
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class TransferProtocolClient extends NetworkClient {
|
||||
code = -1;
|
||||
} else {
|
||||
try {
|
||||
code = Integer.parseInt(response.substring(0, 3));
|
||||
code = Integer.parseInt(response, 0, 3, 10);
|
||||
} catch (NumberFormatException e) {
|
||||
code = -1;
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
|
||||
@ -260,8 +260,8 @@ public class FtpClient extends sun.net.ftp.FtpClient {
|
||||
if (d != null && time != null) {
|
||||
int c = time.indexOf(':');
|
||||
now.setTime(d);
|
||||
now.set(Calendar.HOUR, Integer.parseInt(time.substring(0, c)));
|
||||
now.set(Calendar.MINUTE, Integer.parseInt(time.substring(c + 1)));
|
||||
now.set(Calendar.HOUR, Integer.parseInt(time, 0, c, 10));
|
||||
now.set(Calendar.MINUTE, Integer.parseInt(time, c + 1, time.length(), 10));
|
||||
d = now.getTime();
|
||||
}
|
||||
// see if it's a symbolic link, i.e. the name if followed
|
||||
@ -437,7 +437,7 @@ public class FtpClient extends sun.net.ftp.FtpClient {
|
||||
code = -1;
|
||||
} else {
|
||||
try {
|
||||
code = Integer.parseInt(response.substring(0, 3));
|
||||
code = Integer.parseInt(response, 0, 3, 10);
|
||||
} catch (NumberFormatException e) {
|
||||
code = -1;
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
|
||||
@ -161,7 +161,7 @@ public class ParseUtil {
|
||||
* Un-escape and return the character at position i in string s.
|
||||
*/
|
||||
private static byte unescape(String s, int i) {
|
||||
return (byte) Integer.parseInt(s.substring(i+1,i+3),16);
|
||||
return (byte) Integer.parseInt(s, i + 1, i + 3, 16);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -313,7 +313,7 @@ class ChunkedInputStream extends InputStream implements Hurryable {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
chunkSize = Integer.parseInt(header.substring(0, i), 16);
|
||||
chunkSize = Integer.parseInt(header, 0, i, 16);
|
||||
} catch (NumberFormatException e) {
|
||||
error = true;
|
||||
throw new IOException("Bogus chunk size");
|
||||
|
||||
@ -808,7 +808,7 @@ public class HttpClient extends NetworkClient {
|
||||
ind = resp.indexOf(' ');
|
||||
while(resp.charAt(ind) == ' ')
|
||||
ind++;
|
||||
code = Integer.parseInt(resp.substring(ind, ind + 3));
|
||||
code = Integer.parseInt(resp, ind, ind + 3, 10);
|
||||
} catch (Exception e) {}
|
||||
|
||||
if (code == HTTP_CONTINUE && ignoreContinue) {
|
||||
|
||||
@ -257,7 +257,8 @@ public class SdpProvider extends NetHooks.Provider {
|
||||
.getByName(s[1].substring(0, pos));
|
||||
int prefix = -1;
|
||||
try {
|
||||
prefix = Integer.parseInt(s[1].substring(pos+1));
|
||||
prefix = Integer.parseInt(s[1], pos + 1,
|
||||
s[1].length(), 10);
|
||||
if (address instanceof Inet4Address) {
|
||||
// must be 1-31
|
||||
if (prefix < 0 || prefix > 32) prefix = -1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user