mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
4855. [bug] isc_time_formatshorttimestamp produced incorrect
output. [RT #46938]
This commit is contained in:
parent
7258b852cf
commit
1e10ef06ce
3
CHANGES
3
CHANGES
@ -1,3 +1,6 @@
|
|||||||
|
4855. [bug] isc_time_formatshorttimestamp produced incorrect
|
||||||
|
output. [RT #46938]
|
||||||
|
|
||||||
4854. [bug] query_synthcnamewildcard should stop generating the
|
4854. [bug] query_synthcnamewildcard should stop generating the
|
||||||
response if query_synthwildcard fails. [RT #46939]
|
response if query_synthwildcard fails. [RT #46939]
|
||||||
|
|
||||||
|
@ -182,6 +182,37 @@ ATF_TC_BODY(isc_time_formatISO8601Lms, tc) {
|
|||||||
ATF_CHECK_STREQ(buf, "2015-12-13T01:46:40.123");
|
ATF_CHECK_STREQ(buf, "2015-12-13T01:46:40.123");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATF_TC(isc_time_formatshorttimestamp);
|
||||||
|
ATF_TC_HEAD(isc_time_formatshorttimestamp, tc) {
|
||||||
|
atf_tc_set_md_var(tc, "descr",
|
||||||
|
"print UTC time as yyyymmddhhmmsssss");
|
||||||
|
}
|
||||||
|
ATF_TC_BODY(isc_time_formatshorttimestamp, tc) {
|
||||||
|
isc_result_t result;
|
||||||
|
isc_time_t t;
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
setenv("TZ", "PST8PDT", 1);
|
||||||
|
result = isc_time_now(&t);
|
||||||
|
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
|
/* check formatting: yyyymmddhhmmsssss */
|
||||||
|
memset(buf, 'X', sizeof(buf));
|
||||||
|
isc_time_formatshorttimestamp(&t, buf, sizeof(buf));
|
||||||
|
ATF_CHECK_EQ(strlen(buf), 17);
|
||||||
|
|
||||||
|
/* check time conversion correctness */
|
||||||
|
memset(buf, 'X', sizeof(buf));
|
||||||
|
isc_time_settoepoch(&t);
|
||||||
|
isc_time_formatshorttimestamp(&t, buf, sizeof(buf));
|
||||||
|
ATF_CHECK_STREQ(buf, "19700101000000000");
|
||||||
|
|
||||||
|
memset(buf, 'X', sizeof(buf));
|
||||||
|
isc_time_set(&t, 1450000000, 123000000);
|
||||||
|
isc_time_formatshorttimestamp(&t, buf, sizeof(buf));
|
||||||
|
ATF_CHECK_STREQ(buf, "20151213094640123");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main
|
* Main
|
||||||
*/
|
*/
|
||||||
@ -191,6 +222,6 @@ ATF_TP_ADD_TCS(tp) {
|
|||||||
ATF_TP_ADD_TC(tp, isc_time_formatISO8601ms);
|
ATF_TP_ADD_TC(tp, isc_time_formatISO8601ms);
|
||||||
ATF_TP_ADD_TC(tp, isc_time_formatISO8601L);
|
ATF_TP_ADD_TC(tp, isc_time_formatISO8601L);
|
||||||
ATF_TP_ADD_TC(tp, isc_time_formatISO8601Lms);
|
ATF_TP_ADD_TC(tp, isc_time_formatISO8601Lms);
|
||||||
|
ATF_TP_ADD_TC(tp, isc_time_formatshorttimestamp);
|
||||||
return (atf_no_error());
|
return (atf_no_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,6 +552,9 @@ isc_time_formatshorttimestamp(const isc_time_t *t, char *buf, unsigned int len)
|
|||||||
struct tm tm;
|
struct tm tm;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
REQUIRE(t != NULL);
|
||||||
|
INSIST(t->nanoseconds < NS_PER_S);
|
||||||
|
REQUIRE(buf != NULL);
|
||||||
REQUIRE(len > 0);
|
REQUIRE(len > 0);
|
||||||
|
|
||||||
now = (time_t)t->seconds;
|
now = (time_t)t->seconds;
|
||||||
@ -562,7 +565,6 @@ isc_time_formatshorttimestamp(const isc_time_t *t, char *buf, unsigned int len)
|
|||||||
#endif
|
#endif
|
||||||
INSIST(flen < len);
|
INSIST(flen < len);
|
||||||
if (flen > 0U && len - flen >= 5) {
|
if (flen > 0U && len - flen >= 5) {
|
||||||
flen -= 1; /* rewind one character (Z) */
|
|
||||||
snprintf(buf + flen, len - flen, "%03u",
|
snprintf(buf + flen, len - flen, "%03u",
|
||||||
t->nanoseconds / NS_PER_MS);
|
t->nanoseconds / NS_PER_MS);
|
||||||
}
|
}
|
||||||
|
@ -442,7 +442,10 @@ isc_time_formatshorttimestamp(const isc_time_t *t, char *buf, unsigned int len)
|
|||||||
|
|
||||||
/* strtime() format: "%Y%m%d%H%M%SSSS" */
|
/* strtime() format: "%Y%m%d%H%M%SSSS" */
|
||||||
|
|
||||||
|
REQUIRE(t != NULL);
|
||||||
|
REQUIRE(buf != NULL);
|
||||||
REQUIRE(len > 0);
|
REQUIRE(len > 0);
|
||||||
|
|
||||||
if (FileTimeToSystemTime(&t->absolute, &st)) {
|
if (FileTimeToSystemTime(&t->absolute, &st)) {
|
||||||
GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyyMMdd",
|
GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyyMMdd",
|
||||||
DateBuf, 50);
|
DateBuf, 50);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user