From 087ae4a856994d8405463a3cc770eae1afe830a4 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Tue, 28 Nov 2017 17:12:37 +0100
Subject: [PATCH] check length before checking first character in
 RRuntime.parseInt

---
 .../src/com/oracle/truffle/r/runtime/RRuntime.java   | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
index b1bc38b64b..589957931b 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RRuntime.java
@@ -361,6 +361,9 @@ public class RRuntime {
     @TruffleBoundary
     public static int parseInt(String s) {
         int length = s.length();
+        if (length == 0) {
+            throw new NumberFormatException();
+        }
         long value = 0;
         if (s.charAt(0) == '-') {
             if (length == 1) {
@@ -379,9 +382,6 @@ public class RRuntime {
             }
             return (int) -value;
         } else {
-            if (length == 0) {
-                throw new NumberFormatException();
-            }
             int pos = 0;
             while (pos < length) {
                 char ch = s.charAt(pos++);
@@ -400,6 +400,9 @@ public class RRuntime {
     @TruffleBoundary
     public static int parseIntWithNA(String s) {
         int length = s.length();
+        if (length == 0) {
+            return INT_NA;
+        }
         long value = 0;
         if (s.charAt(0) == '-') {
             if (length == 1) {
@@ -418,9 +421,6 @@ public class RRuntime {
             }
             return (int) -value;
         } else {
-            if (length == 0) {
-                return INT_NA;
-            }
             int pos = 0;
             while (pos < length) {
                 char ch = s.charAt(pos++);
-- 
GitLab