Skip to content

Commit cf7088d

Browse files
committed
[lib] Added exception for required length of caret stops array
1 parent 99cc2fb commit cf7088d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tehreer-android/src/main/java/com/mta/tehreer/sfnt/ShapingResult.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mta.tehreer.sfnt;
1818

1919
import androidx.annotation.NonNull;
20+
import androidx.annotation.Nullable;
2021

2122
import com.mta.tehreer.Disposable;
2223
import com.mta.tehreer.collections.FloatList;
@@ -238,10 +239,15 @@ public int getGlyphCount() {
238239
* @param caretStops An array for caret stops of the code units represented by this object.
239240
* @return A list of caret edges.
240241
*/
241-
public @NonNull FloatList getCaretEdges(boolean[] caretStops) {
242+
public @NonNull FloatList getCaretEdges(@Nullable boolean[] caretStops) {
242243
int charCount = getCharCount();
243-
float[] caretEdges = new float[charCount + 1];
244+
if (caretStops != null) {
245+
if (caretStops.length < charCount) {
246+
throw new IllegalArgumentException("The length of caret stops array must be at least the represented character count");
247+
}
248+
}
244249

250+
float[] caretEdges = new float[charCount + 1];
245251
nGetCaretEdges(nativeResult, caretStops, caretEdges);
246252

247253
return FloatList.of(caretEdges);

0 commit comments

Comments
 (0)