Modified:
branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java
Log:
Fixed BUG#16169 - ResultSet.getNativeShort() causes stack overflow error
via recurisve calls.
Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-01-04 01:03:16 UTC (rev 4772)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/ResultSet.java 2006-01-05 00:14:09 UTC (rev 4773)
@@ -7684,13 +7684,15 @@
return (short)(tinyintVal + (short)256);
case MysqlDefs.FIELD_TYPE_SHORT:
case MysqlDefs.FIELD_TYPE_YEAR:
- short asShort = getNativeShort(columnIndex + 1);
+ byte[] bits = (byte[]) this.thisRow[columnIndex];
+ short asShort = (short) ((bits[0] & 0xff) | ((bits[1] & 0xff) << 8));
+
if (!f.isUnsigned()) {
return asShort;
}
- int valueAsInt = asShort + 65536;
+ int valueAsInt = asShort & 0xffff;
if (this.connection.getJdbcCompliantTruncation() &&
valueAsInt > Short.MAX_VALUE) {
@@ -7699,16 +7701,34 @@
}
return (short)valueAsInt;
+
case MysqlDefs.FIELD_TYPE_INT24:
case MysqlDefs.FIELD_TYPE_LONG:
- byte[] bits = (byte[]) this.thisRow[columnIndex];
-
- valueAsInt = (bits[0] & 0xff) | ((bits[1] & 0xff) << 8)
- | ((bits[2] & 0xff) << 16) | ((bits[3] & 0xff) << 24);
-
- return (short)valueAsInt;
+ if (!f.isUnsigned()) {
+ valueAsInt = getNativeInt(columnIndex + 1);
+
+ if (this.connection.getJdbcCompliantTruncation() &&
+ valueAsInt > Short.MAX_VALUE ||
+ valueAsInt < Short.MIN_VALUE) {
+ throwRangeException(String.valueOf(valueAsInt),
+ columnIndex + 1, Types.SMALLINT);
+ }
+
+ return (short)valueAsInt;
+ }
+
+ long valueAsLong = getNativeLong(columnIndex + 1);
+
+ if (this.connection.getJdbcCompliantTruncation() &&
+ valueAsLong > Short.MAX_VALUE) {
+ throwRangeException(String.valueOf(valueAsLong),
+ columnIndex + 1, Types.SMALLINT);
+ }
+
+ return (short)valueAsLong;
+
case MysqlDefs.FIELD_TYPE_LONGLONG:
- long valueAsLong = getNativeLong(columnIndex + 1);
+ valueAsLong = getNativeLong(columnIndex + 1);
if (this.connection.getJdbcCompliantTruncation()) {
if (valueAsLong < Integer.MIN_VALUE