[Pkg-nagios-devel] Bug#289762: problem seems to be in FROM_UNIXTIME()
sean finney
sean finney <seanius@debian.org>, 289762@bugs.debian.org
Thu, 13 Jan 2005 17:30:52 -0500
--i9LlY+UWpKt15+FH
Content-Type: multipart/mixed; boundary="sdtB3X0nJg68CQEu"
Content-Disposition: inline
--sdtB3X0nJg68CQEu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
tags 289762 patch
thanks
whoops. here's the patch :)
sean
--sdtB3X0nJg68CQEu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="from_unixtime_epoch.patch"
Content-Transfer-Encoding: quoted-printable
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2004/12/30 21:18:10+03:00 dlenev@mysql.com=20
# Fix for bug #7515 "from_unixtime(0) now returns NULL instead of
# the Epoch". (With after review fixes).
#=20
# mysql-test/r/func_time.result
# 2004/12/30 21:18:06+03:00 dlenev@mysql.com +5 -2
# Added test for bug #7515 "from_unixtime(0) now returns NULL instead of
# the Epoch".
#=20
# mysql-test/t/func_time.test
# 2004/12/30 21:18:07+03:00 dlenev@mysql.com +6 -2
# Added test for bug #7515 "from_unixtime(0) now returns NULL instead of
# the Epoch".
#=20
# sql/item_timefunc.cc
# 2004/12/30 21:18:07+03:00 dlenev@mysql.com +6 -4
# Item_func_from_unixtime:
# from_unixtime(0) should return Epoch instead of NULL.
#=20
# sql/item_timefunc.h
# 2004/12/30 21:18:07+03:00 dlenev@mysql.com +1 -2
# Item_func_from_unixtime:
# - Removed unused method definition.
# - fix_length_and_dec() should set maybe_null to true since now
# from_unixtime() can return NULL even in case when none of its
# arguments is NULL.
#=20
diff -Nru a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
--- a/mysql-test/r/func_time.result 2005-01-13 14:05:48 -08:00
+++ b/mysql-test/r/func_time.result 2005-01-13 14:05:48 -08:00
@@ -470,9 +470,12 @@
select unix_timestamp('1969-12-01 19:00:01');
unix_timestamp('1969-12-01 19:00:01')
0
-select from_unixtime(0);
-from_unixtime(0)
+select from_unixtime(-1);
+from_unixtime(-1)
NULL
select from_unixtime(2145916800);
from_unixtime(2145916800)
NULL
+select from_unixtime(0);
+from_unixtime(0)
+1970-01-01 03:00:00
diff -Nru a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
--- a/mysql-test/t/func_time.test 2005-01-13 14:05:48 -08:00
+++ b/mysql-test/t/func_time.test 2005-01-13 14:05:48 -08:00
@@ -228,7 +228,11 @@
=20
#
# Test for bug #6439 "unix_timestamp() function returns wrong datetime=20
-# values for too big argument". It should return error instead.
+# values for too big argument" and bug #7515 "from_unixtime(0) now
+# returns NULL instead of the epoch". unix_timestamp() should return error
+# for too big or negative argument. It should return Epoch value for zero
+# argument since it seems that many user's rely on this fact.
#
-select from_unixtime(0);
+select from_unixtime(-1);
select from_unixtime(2145916800);
+select from_unixtime(0);
diff -Nru a/sql/item_timefunc.cc b/sql/item_timefunc.cc
--- a/sql/item_timefunc.cc 2005-01-13 14:05:48 -08:00
+++ b/sql/item_timefunc.cc 2005-01-13 14:05:48 -08:00
@@ -946,10 +946,12 @@
{
struct tm tm_tmp;
time_t tmp;
- longlong arg=3D args[0]->val_int();
- if ((null_value=3D (args[0]->null_value ||
- arg < TIMESTAMP_MIN_VALUE ||
- arg > TIMESTAMP_MAX_VALUE)))
+ ulonglong arg=3D (ulonglong)(args[0]->val_int());
+ /*
+ "arg > TIMESTAMP_MAX_VALUE" check also covers case of negative
+ from_unixtime() argument since arg is unsigned.
+ */
+ if ((null_value=3D (args[0]->null_value || arg > TIMESTAMP_MAX_VALUE)))
return 1;
tmp=3D arg;
localtime_r(&tmp,&tm_tmp);
diff -Nru a/sql/item_timefunc.h b/sql/item_timefunc.h
--- a/sql/item_timefunc.h 2005-01-13 14:05:48 -08:00
+++ b/sql/item_timefunc.h 2005-01-13 14:05:48 -08:00
@@ -359,8 +359,7 @@
longlong val_int();
String *val_str(String *str);
const char *func_name() const { return "from_unixtime"; }
- void fix_length_and_dec() { decimals=3D0; max_length=3D19; }
-// enum Item_result result_type () const { return STRING_RESULT; }
+ void fix_length_and_dec() { decimals=3D0; max_length=3D19; maybe_null=3D=
1; }
bool get_date(TIME *res,bool fuzzy_date);
};
=20
--sdtB3X0nJg68CQEu--
--i9LlY+UWpKt15+FH
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFB5vacynjLPm522B0RAlVBAJ9ACs22BO848X6VFnRj0lw6WpeGgACeNahu
A/sqStmtBgJznfRigYVduZY=
=7M1H
-----END PGP SIGNATURE-----
--i9LlY+UWpKt15+FH--