Validate index for cursor on BiDi text

Previously we have updated the code not to check mHorizontals if offset
is invalid (I5c5778718f6b397adbb1e4f2cf95e9f635f6e5c8) However we should
also check the final index to make sure no invalid index is accessed.

Test: None

Bug: 111580019
Change-Id: I5c32820cde5f91bfe8688e9394b8ba3254cbd731
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index c6c1e8a..3633808 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -1594,10 +1594,11 @@
         }
 
         float get(final int offset) {
-            if (mHorizontals == null || offset < 0 || offset >= mHorizontals.length) {
+            final int index = offset - mLineStartOffset;
+            if (mHorizontals == null || index < 0 || index >= mHorizontals.length) {
                 return getHorizontal(offset, mPrimary);
             } else {
-                return mHorizontals[offset - mLineStartOffset];
+                return mHorizontals[index];
             }
         }
     }