Skip to content
Snippets Groups Projects
Commit 52435bd2 authored by stepan's avatar stepan
Browse files

Fix index out of bounds in CastSymbolNode when the vector is empty

parent b387e595
No related branches found
No related tags found
No related merge requests found
...@@ -85,27 +85,37 @@ public abstract class CastSymbolNode extends CastBaseNode { ...@@ -85,27 +85,37 @@ public abstract class CastSymbolNode extends CastBaseNode {
return RDataFactory.createSymbolInterned(value); return RDataFactory.createSymbolInterned(value);
} }
@Specialization @Specialization(guards = "value.getLength() > 0")
protected RSymbol doStringVector(RStringVector value) { protected RSymbol doStringVector(RStringVector value) {
// Only element 0 interpreted // Only element 0 interpreted
return doString(value.getDataAt(0)); return doString(value.getDataAt(0));
} }
@Specialization @Specialization(guards = "value.getLength() > 0")
protected RSymbol doIntegerVector(RIntVector value) { protected RSymbol doIntegerVector(RIntVector value) {
return doInteger(value.getDataAt(0)); return doInteger(value.getDataAt(0));
} }
@Specialization @Specialization(guards = "value.getLength() > 0")
protected RSymbol doDoubleVector(RDoubleVector value) { protected RSymbol doDoubleVector(RDoubleVector value) {
return doDouble(value.getDataAt(0)); return doDouble(value.getDataAt(0));
} }
@Specialization @Specialization(guards = "value.getLength() > 0")
protected RSymbol doLogicalVector(RLogicalVector value) { protected RSymbol doLogicalVector(RLogicalVector value) {
return doLogical(value.getDataAt(0)); return doLogical(value.getDataAt(0));
} }
@Specialization(guards = "vector.getLength() == 0")
@TruffleBoundary
protected RSymbol doEmptyVector(RAbstractVector vector) {
if (vector instanceof RList) {
throw RError.error(this, RError.Message.INVALID_TYPE_LENGTH, "symbol", 0);
} else {
throw RError.error(this, Message.INVALID_DATA_OF_TYPE_TOO_SHORT, vector.getRType().getName(), 0);
}
}
@TruffleBoundary @TruffleBoundary
private static RSymbol asSymbol(String s) { private static RSymbol asSymbol(String s) {
return RDataFactory.createSymbolInterned(s); return RDataFactory.createSymbolInterned(s);
......
...@@ -236,6 +236,7 @@ public final class RError extends RuntimeException { ...@@ -236,6 +236,7 @@ public final class RError extends RuntimeException {
*/ */
GENERIC("%s"), GENERIC("%s"),
TOO_SHORT("'%s' is too short"), TOO_SHORT("'%s' is too short"),
INVALID_DATA_OF_TYPE_TOO_SHORT("invalid data of mode '%s' (too short)"),
VECTOR_SIZE_TOO_LARGE("vector size specified is too large"), VECTOR_SIZE_TOO_LARGE("vector size specified is too large"),
ARG_RECYCYLED("an argument will be fractionally recycled"), ARG_RECYCYLED("an argument will be fractionally recycled"),
LENGTH_GT_1("the condition has length > 1 and only the first element will be used"), LENGTH_GT_1("the condition has length > 1 and only the first element will be used"),
......
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