Skip to content

Commit 9ffdd1c

Browse files
author
Tor Didriksen
committed
Bug #50087 Interval arithmetic for Event_queue_element is not portable.
Subtraction of two unsigned months yielded a (very large) positive value. Conversion of this to a signed value was not necessarily well defined. Solution: do the subtraction on signed values.
1 parent 8214891 commit 9ffdd1c

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

mysql-test/r/events_scheduling.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,24 @@ DROP TABLE table_1;
8282
DROP TABLE table_2;
8383
DROP TABLE table_3;
8484
DROP TABLE table_4;
85+
86+
Bug #50087 Interval arithmetic for Event_queue_element is not portable.
87+
88+
CREATE TABLE t1(a int);
89+
CREATE EVENT e1 ON SCHEDULE EVERY 1 MONTH
90+
STARTS NOW() - INTERVAL 1 MONTH
91+
ENDS NOW() + INTERVAL 2 MONTH
92+
ON COMPLETION PRESERVE
93+
DO
94+
INSERT INTO t1 VALUES (1);
95+
CREATE EVENT e2 ON SCHEDULE EVERY 1 MONTH
96+
STARTS NOW()
97+
ENDS NOW() + INTERVAL 11 MONTH
98+
ON COMPLETION PRESERVE
99+
DO
100+
INSERT INTO t1 VALUES (1);
101+
DROP TABLE t1;
102+
DROP EVENT e1;
103+
DROP EVENT e2;
85104
DROP DATABASE events_test;
86105
SET GLOBAL event_scheduler=@event_scheduler;

mysql-test/t/events_scheduling.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,32 @@ DROP TABLE table_1;
108108
DROP TABLE table_2;
109109
DROP TABLE table_3;
110110
DROP TABLE table_4;
111+
112+
-- echo
113+
-- echo Bug #50087 Interval arithmetic for Event_queue_element is not portable.
114+
-- echo
115+
116+
CREATE TABLE t1(a int);
117+
118+
CREATE EVENT e1 ON SCHEDULE EVERY 1 MONTH
119+
STARTS NOW() - INTERVAL 1 MONTH
120+
ENDS NOW() + INTERVAL 2 MONTH
121+
ON COMPLETION PRESERVE
122+
DO
123+
INSERT INTO t1 VALUES (1);
124+
125+
CREATE EVENT e2 ON SCHEDULE EVERY 1 MONTH
126+
STARTS NOW()
127+
ENDS NOW() + INTERVAL 11 MONTH
128+
ON COMPLETION PRESERVE
129+
DO
130+
INSERT INTO t1 VALUES (1);
131+
132+
DROP TABLE t1;
133+
DROP EVENT e1;
134+
DROP EVENT e2;
135+
136+
111137
DROP DATABASE events_test;
112138
SET GLOBAL event_scheduler=@event_scheduler;
113139

sql/event_data_objects.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,9 @@ bool get_next_time(const Time_zone *time_zone, my_time_t *next,
834834
}
835835
else
836836
{
837-
long diff_months= (long) (local_now.year - local_start.year)*12 +
838-
(local_now.month - local_start.month);
837+
long diff_months= ((long) local_now.year - (long) local_start.year)*12 +
838+
((long) local_now.month - (long) local_start.month);
839+
839840
/*
840841
Unlike for seconds above, the formula below returns the interval
841842
that, when added to the local_start, will give the time in the

0 commit comments

Comments
 (0)