Skip to content

Commit 2221c6a

Browse files
committed
fix warning: ensure to check unused variable
1 parent 996438e commit 2221c6a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/mysql2/result.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
283283
int tokens;
284284
unsigned int hour=0, min=0, sec=0;
285285
tokens = sscanf(row[i], "%2u:%2u:%2u", &hour, &min, &sec);
286+
if (tokens < 3) {
287+
val = Qnil;
288+
break;
289+
}
286290
val = rb_funcall(rb_cTime, db_timezone, 6, opt_time_year, opt_time_month, opt_time_month, UINT2NUM(hour), UINT2NUM(min), UINT2NUM(sec));
287291
if (!NIL_P(app_timezone)) {
288292
if (app_timezone == intern_local) {
@@ -300,6 +304,10 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
300304
uint64_t seconds;
301305

302306
tokens = sscanf(row[i], "%4u-%2u-%2u %2u:%2u:%2u.%6u", &year, &month, &day, &hour, &min, &sec, &msec);
307+
if (tokens < 6) { /* msec might be empty */
308+
val = Qnil;
309+
break;
310+
}
303311
seconds = (year*31557600ULL) + (month*2592000ULL) + (day*86400ULL) + (hour*3600ULL) + (min*60ULL) + sec;
304312

305313
if (seconds == 0) {
@@ -342,6 +350,10 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
342350
int tokens;
343351
unsigned int year=0, month=0, day=0;
344352
tokens = sscanf(row[i], "%4u-%2u-%2u", &year, &month, &day);
353+
if (tokens < 3) {
354+
val = Qnil;
355+
break;
356+
}
345357
if (year+month+day == 0) {
346358
val = Qnil;
347359
} else {

0 commit comments

Comments
 (0)