summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-08-11 19:12:13 +0400
committerAlexander Barkov <bar@mariadb.com>2018-08-11 19:12:13 +0400
commit7a022d706155cb2ac00936d6829883b40af7f147 (patch)
tree2688e55bead181720dd75330769ea758c5909fb5
parent73a5dd8c54a12fd5efaa90df6a99dad73aee1679 (diff)
downloadmariadb-git-7a022d706155cb2ac00936d6829883b40af7f147.tar.gz
A cleanup for MDEV-16939: avoid timeval initialization related problems in the future (compilation failures on Windows)
Adding a helper class Timeval, to initialize "struct timeval" in a safe way. As a bonus, adding a method Timeval::trunc(), so the caller now can have one line instead of five lines (declaration, initializations of sec and usec, truncation, passing to store_TIMEVAL()).
-rw-r--r--sql/field.cc7
-rw-r--r--sql/field.h6
-rw-r--r--sql/structs.h16
3 files changed, 18 insertions, 11 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 4b1c2397a58..e014b62788a 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -5059,12 +5059,7 @@ int Field_timestamp::store_TIME_with_warning(THD *thd, const Datetime *dt,
}
// Adjust and store the value
- timeval tv;
- tv.tv_sec= timestamp;
- tv.tv_usec= l_time->second_part;
-
- my_timeval_trunc(&tv, decimals());
- store_TIMEVAL(tv);
+ store_TIMEVAL(Timeval(timestamp, l_time->second_part).trunc(decimals()));
// Calculate return value and send warnings if needed
if (unlikely(conversion_error)) // e.g. DATETIME in the DST gap
diff --git a/sql/field.h b/sql/field.h
index b35b31bb444..8b080a0d06f 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -2756,11 +2756,7 @@ public:
}
void store_TIME(my_time_t timestamp, ulong sec_part)
{
- timeval tv;
- tv.tv_sec= timestamp;
- tv.tv_usec= sec_part;
- my_timeval_trunc(&tv, decimals());
- store_TIMEVAL(tv);
+ store_TIMEVAL(Timeval(timestamp, sec_part).trunc(decimals()));
}
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
uchar *pack(uchar *to, const uchar *from,
diff --git a/sql/structs.h b/sql/structs.h
index 21b3904faa4..355d6e75e48 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -831,4 +831,20 @@ public:
};
+class Timeval: public timeval
+{
+public:
+ Timeval(my_time_t sec, ulong usec)
+ {
+ tv_sec= sec;
+ tv_usec= usec;
+ }
+ Timeval &trunc(uint dec)
+ {
+ my_timeval_trunc(this, dec);
+ return *this;
+ }
+};
+
+
#endif /* STRUCTS_INCLUDED */