Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
225842de
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
225842de
编写于
1月 28, 2017
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CCTZ: added diagnostics [#CLICKHOUSE-2782].
上级
7f73f917
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
3 deletion
+55
-3
contrib/libcctz/src/time_zone_info.cc
contrib/libcctz/src/time_zone_info.cc
+55
-3
未找到文件。
contrib/libcctz/src/time_zone_info.cc
浏览文件 @
225842de
...
...
@@ -359,45 +359,76 @@ bool TimeZoneInfo::Load(const std::string& name, FILE* fp) {
// Read and validate the header.
tzhead
tzh
;
if
(
fread
(
&
tzh
,
1
,
sizeof
tzh
,
fp
)
!=
sizeof
tzh
)
{
std
::
cerr
<<
"Cannot read tz header
\n
"
;
return
false
;
}
if
(
strncmp
(
tzh
.
tzh_magic
,
TZ_MAGIC
,
sizeof
(
tzh
.
tzh_magic
))
!=
0
)
{
std
::
cerr
<<
"Cannot read tz magic
\n
"
;
return
false
;
}
Header
hdr
;
hdr
.
Build
(
tzh
);
std
::
size_t
time_len
=
4
;
if
(
tzh
.
tzh_version
[
0
]
!=
'\0'
)
{
// Skip the 4-byte data.
if
(
fseek
(
fp
,
static_cast
<
long
>
(
hdr
.
DataLength
(
time_len
)),
SEEK_CUR
)
!=
0
)
return
false
;
{
std
::
cerr
<<
"Cannot seek
\n
"
;
return
false
;
}
// Read and validate the header for the 8-byte data.
if
(
fread
(
&
tzh
,
1
,
sizeof
tzh
,
fp
)
!=
sizeof
tzh
)
return
false
;
{
std
::
cerr
<<
"Cannot read tz header, again
\n
"
;
return
false
;
}
if
(
strncmp
(
tzh
.
tzh_magic
,
TZ_MAGIC
,
sizeof
(
tzh
.
tzh_magic
))
!=
0
)
return
false
;
{
std
::
cerr
<<
"Cannot read tz magic (again)
\n
"
;
return
false
;
}
if
(
tzh
.
tzh_version
[
0
]
==
'\0'
)
{
std
::
cerr
<<
"tzh version != 0
\n
"
;
return
false
;
}
hdr
.
Build
(
tzh
);
time_len
=
8
;
}
if
(
hdr
.
timecnt
<
0
||
hdr
.
typecnt
<=
0
)
{
std
::
cerr
<<
"Wrong cnt
\n
"
;
return
false
;
}
if
(
hdr
.
leapcnt
!=
0
)
{
// This code assumes 60-second minutes so we do not want
// the leap-second encoded zoneinfo. We could reverse the
// compensation, but it's never in a Google zoneinfo anyway,
// so currently we simply reject such data.
std
::
cerr
<<
"Doesnt support leap second encoded tzinfo
\n
"
;
return
false
;
}
if
(
hdr
.
ttisstdcnt
!=
0
&&
hdr
.
ttisstdcnt
!=
hdr
.
typecnt
)
{
std
::
cerr
<<
"Wrong cnt (2)
\n
"
;
return
false
;
}
if
(
hdr
.
ttisgmtcnt
!=
0
&&
hdr
.
ttisgmtcnt
!=
hdr
.
typecnt
)
{
std
::
cerr
<<
"Wrong cnt (3)
\n
"
;
return
false
;
}
// Read the data into a local buffer.
std
::
size_t
len
=
hdr
.
DataLength
(
time_len
);
std
::
vector
<
char
>
tbuf
(
len
);
if
(
fread
(
tbuf
.
data
(),
1
,
len
,
fp
)
!=
len
)
{
std
::
cerr
<<
"Cannot read data
\n
"
;
return
false
;
}
const
char
*
bp
=
tbuf
.
data
();
// Decode and validate the transitions.
...
...
@@ -409,14 +440,20 @@ bool TimeZoneInfo::Load(const std::string& name, FILE* fp) {
if
(
i
!=
0
)
{
// Check that the transitions are ordered by time (as zic guarantees).
if
(
!
Transition
::
ByUnixTime
()(
transitions_
[
i
-
1
],
transitions_
[
i
]))
{
std
::
cerr
<<
"Data is out of order
\n
"
;
return
false
;
// out of order
}
}
}
bool
seen_type_0
=
false
;
for
(
std
::
int_fast32_t
i
=
0
;
i
!=
hdr
.
timecnt
;
++
i
)
{
transitions_
[
i
].
type_index
=
Decode8
(
bp
++
);
if
(
transitions_
[
i
].
type_index
>=
hdr
.
typecnt
)
{
std
::
cerr
<<
"Type index is out of range
\n
"
;
return
false
;
}
if
(
transitions_
[
i
].
type_index
==
0
)
seen_type_0
=
true
;
}
...
...
@@ -427,12 +464,18 @@ bool TimeZoneInfo::Load(const std::string& name, FILE* fp) {
transition_types_
[
i
].
utc_offset
=
Decode32
(
bp
);
if
(
transition_types_
[
i
].
utc_offset
>=
SECSPERDAY
||
transition_types_
[
i
].
utc_offset
<=
-
SECSPERDAY
)
{
std
::
cerr
<<
"Wrong transition offset
\n
"
;
return
false
;
}
bp
+=
4
;
transition_types_
[
i
].
is_dst
=
(
Decode8
(
bp
++
)
!=
0
);
transition_types_
[
i
].
abbr_index
=
Decode8
(
bp
++
);
if
(
transition_types_
[
i
].
abbr_index
>=
hdr
.
charcnt
)
{
std
::
cerr
<<
"Transition abbr index is out of range
\n
"
;
return
false
;
}
}
// Determine the before-first-transition type.
...
...
@@ -467,10 +510,16 @@ bool TimeZoneInfo::Load(const std::string& name, FILE* fp) {
// Snarf up the NL-enclosed future POSIX spec. Note
// that version '3' files utilize an extended format.
if
(
fgetc
(
fp
)
!=
'\n'
)
{
std
::
cerr
<<
"Cannot read posix spec (1)
\n
"
;
return
false
;
}
for
(
int
c
=
fgetc
(
fp
);
c
!=
'\n'
;
c
=
fgetc
(
fp
))
{
if
(
c
==
EOF
)
{
std
::
cerr
<<
"Cannot read posix spec (2)
\n
"
;
return
false
;
}
future_spec_
.
push_back
(
static_cast
<
char
>
(
c
));
}
}
...
...
@@ -519,7 +568,10 @@ bool TimeZoneInfo::Load(const std::string& name, FILE* fp) {
// this means that an offset change cannot cross another such change.
// No one does this in practice, and we depend on it in MakeTime().
if
(
!
Transition
::
ByDateTime
()(
transitions_
[
i
-
1
],
tr
))
{
std
::
cerr
<<
"Out of order (2)
\n
"
;
return
false
;
// out of order
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录