Skip to content

Commit beb8709

Browse files
committed
Fix int overflow and UT failure on GCC 12 (Fedora 36)
Change-Id: I7a5a1f5c8a623b8931803ffd27503ddab7d41ba3 Change-Id: Iba467a4a357012e37ab9b516f989f91f8dc6769b
1 parent 4e6adc0 commit beb8709

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

driver/mysql_art_resultset.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,26 +257,31 @@ MySQL_ArtResultSet::isBeforeFirstOrAfterLast() const
257257
}
258258
/* }}} */
259259

260+
/* {{{ MySQL_ArtResultSet::absolute() -I-
261+
_new_pos: Seek the passed position on the ResultSet. If _new_pos is negative,
262+
it will count from last to beginning.
260263
261-
/* {{{ MySQL_ArtResultSet::absolute() -I- */
264+
return: true if position is a valid row, false if it pasted last or beginnin
265+
*/
262266
bool
263-
MySQL_ArtResultSet::absolute(const int row)
267+
MySQL_ArtResultSet::absolute(const int _row)
264268
{
265269
CPP_ENTER("MySQL_ArtResultSet::absolute");
266270
checkValid();
271+
const int64_t row = _row;
267272
if (row > 0) {
268-
if (row > (int) num_rows) {
273+
if (row > num_rows) {
269274
afterLast();
270275
} else {
271276
row_position = row;
272277
seek();
273278
return true;
274279
}
275280
} else if (row < 0) {
276-
if ((-row) > (int) num_rows) {
281+
if (-row > num_rows) {
277282
beforeFirst();
278283
} else {
279-
row_position = num_rows - (-row) + 1;
284+
row_position = num_rows + row + 1;
280285
seek();
281286
return true;
282287
}

driver/mysql_ps_resultset.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,33 @@ MySQL_Prepared_ResultSet::~MySQL_Prepared_ResultSet()
126126
}
127127
/* }}} */
128128

129+
/* {{{ MySQL_Prepared_ResultSet::absolute() -I-
130+
_new_pos: Seek the passed position on the ResultSet. If _new_pos is negative,
131+
it will count from last to beginning.
129132
130-
/* {{{ MySQL_Prepared_ResultSet::absolute() -I- */
133+
return: true if position is a valid row, false if it pasted last or beginnin
134+
*/
131135
bool
132-
MySQL_Prepared_ResultSet::absolute(const int new_pos)
136+
MySQL_Prepared_ResultSet::absolute(const int _new_pos)
133137
{
134138
CPP_ENTER("MySQL_Prepared_ResultSet::absolute");
135139
checkValid();
136140
checkScrollable();
137-
if (new_pos > 0) {
138-
if (new_pos > (int) num_rows) {
141+
const int64_t new_pos = _new_pos;
142+
if (new_pos > 0)
143+
{
144+
if (new_pos > num_rows) {
139145
row_position = num_rows + 1; /* after last row */
140146
} else {
141147
row_position = new_pos;
142148
seek();
143149
return true;
144150
}
145151
} else if (new_pos < 0) {
146-
if ((-new_pos) > (int) num_rows || (new_pos == std::numeric_limits<int>::min())) {
152+
if (-new_pos > num_rows) {
147153
row_position = 0; /* before first new_pos */
148154
} else {
149-
row_position = num_rows - (-new_pos) + 1;
155+
row_position = num_rows + new_pos + 1;
150156
seek();
151157
return true;
152158
}

driver/mysql_resultset.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,32 @@ MySQL_ResultSet::~MySQL_ResultSet()
9595
/* }}} */
9696

9797

98-
/* {{{ MySQL_ResultSet::absolute() -I- */
98+
/* {{{ MySQL_ResultSet::absolute() -I-
99+
_new_pos: Seek the passed position on the ResultSet. If _new_pos is negative,
100+
it will count from last to beginning.
101+
102+
return: true if position is a valid row, false if it pasted last or beginnin
103+
*/
99104
bool
100-
MySQL_ResultSet::absolute(const int new_pos)
105+
MySQL_ResultSet::absolute(const int _new_pos)
101106
{
102107
CPP_ENTER("MySQL_ResultSet::absolute");
103108
checkValid();
104109
checkScrollable();
110+
const int64_t new_pos = _new_pos;
105111
if (new_pos > 0) {
106-
if (new_pos > (int) num_rows) {
112+
if (new_pos > num_rows) {
107113
row_position = num_rows + 1; /* after last row */
108114
} else {
109-
row_position = (my_ulonglong) new_pos; /* the cast is inspected and is valid */
115+
row_position = new_pos;
110116
seek();
111117
return true;
112118
}
113119
} else if (new_pos < 0) {
114-
if ((-new_pos) > (int) num_rows || (new_pos == std::numeric_limits<int>::min())) {
120+
if ((-new_pos) > num_rows) {
115121
row_position = 0; /* before first new_pos */
116122
} else {
117-
row_position = num_rows - (-new_pos) + 1;
123+
row_position = num_rows + new_pos + 1;
118124
seek();
119125
return true;
120126
}

0 commit comments

Comments
 (0)