Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for overflows when calling jpy getIntValue #3839

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,33 @@ static int getInt(PyObject valueIn) {
if (valueIn == null) {
return QueryConstants.NULL_INT;
}
return valueIn.getIntValue();
long ll = valueIn.getLongValue();
if ((int) ll != ll) {
throw new ArithmeticException("The PyObject value is outside Integer range.");
}
return (int) ll;
}

static short getShort(PyObject valueIn) {
if (valueIn == null) {
return QueryConstants.NULL_SHORT;
return QueryConstants.NULL_SHORT; // NB: should there be a getShortValue() in jpy?
jmao-denver marked this conversation as resolved.
Show resolved Hide resolved
}
long ll = valueIn.getLongValue();
if ((short) ll != ll) {
throw new ArithmeticException("The PyObject value is outside Short range.");
}
return (short) valueIn.getIntValue(); // NB: should there be a getShortValue() in jpy?
return (short) ll;
}

static byte getByte(PyObject valueIn) {
if (valueIn == null) {
return QueryConstants.NULL_BYTE; // NB: should there be a getByteValue() in jpy?
}
return (byte) valueIn.getIntValue();
long ll = valueIn.getLongValue();
if ((byte) ll != ll) {
throw new ArithmeticException("The PyObject value is outside Byte range.");
}
return (byte) ll;
}

static Boolean getBoolean(PyObject valueIn) {
Expand Down