Skip to content

Commit f819033

Browse files
committed
Merge branch 'v2017'
2 parents a064bb5 + b0ce642 commit f819033

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ CFLAGS=-Wdeclaration-after-statement ${FLAGS}
88

99
CPPFLAGS=${FLAGS}
1010

11-
LDFLAGS=-lm -fsanitize=undefined -l:libubsan.so.1
11+
LDFLAGS=-lm -fsanitize=undefined -l:libubsan.so
1212

1313
TEST_LDFLAGS=-lCppUTest
1414

15-
CC=gcc-8
16-
CXX=g++-8
15+
CC=gcc
16+
CXX=g++
17+
1718
MANUAL_TESTS=tests/tester-parse-interval \
1819
tests/tester-parse-tz tests/tester-iso-week tests/test-abbr-to-id \
1920
tests/enumerate-timezones tests/date_from_isodate

tests/c/issues.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "CppUTest/TestHarness.h"
22
#include "timelib.h"
3+
#include <string.h>
34

45
TEST_GROUP(issues)
56
{
@@ -439,6 +440,38 @@ TEST(issues, issue0065_test2)
439440
offset = timelib_get_time_zone_info(-3852662325, tzi);
440441
LONGS_EQUAL(-3852662325, offset->transition_time);
441442
timelib_time_offset_dtor(offset);
443+
timelib_tzinfo_dtor(tzi);
444+
}
445+
446+
TEST(issues, issue0069)
447+
{
448+
char str1[] = "2019-10-14T15:08:23.123+02:00";
449+
char str2[] = "-50000 msec";
450+
timelib_time *t1 = timelib_strtotime(str1, sizeof(str1), NULL, timelib_builtin_db(), timelib_parse_tzfile);
451+
timelib_time *t2 = timelib_strtotime(str2, sizeof(str2), NULL, timelib_builtin_db(), timelib_parse_tzfile);
452+
int dummy_error;
453+
timelib_tzinfo *tzi;
454+
455+
tzi = timelib_parse_tzfile((char*) "UTC", timelib_builtin_db(), &dummy_error);
456+
457+
timelib_update_ts(t1, tzi);
458+
459+
memcpy(&t1->relative, &t2->relative, sizeof(timelib_rel_time));
460+
t1->have_relative = 1;
461+
t1->sse_uptodate = 0;
462+
463+
timelib_update_ts(t1, NULL);
464+
timelib_update_from_sse(t1);
465+
t1->have_relative = 0;
442466

467+
memset(&t1->relative, 0, sizeof(timelib_rel_time));
468+
469+
LONGS_EQUAL(123000, t1->us);
470+
LONGS_EQUAL(33, t1->s);
471+
LONGS_EQUAL( 7, t1->i);
472+
LONGS_EQUAL(15, t1->h);
473+
474+
timelib_time_dtor(t1);
475+
timelib_time_dtor(t2);
443476
timelib_tzinfo_dtor(tzi);
444477
}

tm2unixtime.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 24
3333
static int days_in_month_leap[13] = { 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3434
static int days_in_month[13] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3535

36-
static void do_range_limit_fraction(timelib_sll *fraction, timelib_sll *seconds)
37-
{
38-
if (*fraction < 0) {
39-
*fraction += 1000000;
40-
*seconds -= 1;
41-
}
42-
if (*fraction >= 1000000) {
43-
*fraction -= 1000000;
44-
*seconds += 1;
45-
}
46-
}
47-
4836
static void do_range_limit(timelib_sll start, timelib_sll end, timelib_sll adj, timelib_sll *a, timelib_sll *b)
4937
{
5038
if (*a < start) {
@@ -194,7 +182,7 @@ static void do_adjust_for_weekday(timelib_time* time)
194182

195183
void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
196184
{
197-
do_range_limit_fraction(&rt->us, &rt->s);
185+
do_range_limit(0, 1000000, 1000000, &rt->us, &rt->s);
198186
do_range_limit(0, 60, 60, &rt->s, &rt->i);
199187
do_range_limit(0, 60, 60, &rt->i, &rt->h);
200188
do_range_limit(0, 24, 24, &rt->h, &rt->d);
@@ -234,7 +222,7 @@ static void magic_date_calc(timelib_time *time)
234222

235223
void timelib_do_normalize(timelib_time* time)
236224
{
237-
if (time->us != TIMELIB_UNSET) do_range_limit_fraction(&time->us, &time->s);
225+
if (time->us != TIMELIB_UNSET) do_range_limit(0, 1000000, 1000000, &time->us, &time->s);
238226
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i);
239227
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h);
240228
if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d);

0 commit comments

Comments
 (0)