Skip to content
Snippets Groups Projects
Commit 087ae4a8 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

check length before checking first character in RRuntime.parseInt

parent 8004eb05
No related branches found
No related tags found
No related merge requests found
...@@ -361,6 +361,9 @@ public class RRuntime { ...@@ -361,6 +361,9 @@ public class RRuntime {
@TruffleBoundary @TruffleBoundary
public static int parseInt(String s) { public static int parseInt(String s) {
int length = s.length(); int length = s.length();
if (length == 0) {
throw new NumberFormatException();
}
long value = 0; long value = 0;
if (s.charAt(0) == '-') { if (s.charAt(0) == '-') {
if (length == 1) { if (length == 1) {
...@@ -379,9 +382,6 @@ public class RRuntime { ...@@ -379,9 +382,6 @@ public class RRuntime {
} }
return (int) -value; return (int) -value;
} else { } else {
if (length == 0) {
throw new NumberFormatException();
}
int pos = 0; int pos = 0;
while (pos < length) { while (pos < length) {
char ch = s.charAt(pos++); char ch = s.charAt(pos++);
...@@ -400,6 +400,9 @@ public class RRuntime { ...@@ -400,6 +400,9 @@ public class RRuntime {
@TruffleBoundary @TruffleBoundary
public static int parseIntWithNA(String s) { public static int parseIntWithNA(String s) {
int length = s.length(); int length = s.length();
if (length == 0) {
return INT_NA;
}
long value = 0; long value = 0;
if (s.charAt(0) == '-') { if (s.charAt(0) == '-') {
if (length == 1) { if (length == 1) {
...@@ -418,9 +421,6 @@ public class RRuntime { ...@@ -418,9 +421,6 @@ public class RRuntime {
} }
return (int) -value; return (int) -value;
} else { } else {
if (length == 0) {
return INT_NA;
}
int pos = 0; int pos = 0;
while (pos < length) { while (pos < length) {
char ch = s.charAt(pos++); char ch = s.charAt(pos++);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment