Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
e1208321
Commit
e1208321
authored
Jun 04, 2021
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix existing use-of-uninitialized-value
parent
979c4f91
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
10 deletions
+12
-10
sysinfo.cc
src/sysinfo.cc
+12
-10
No files found.
src/sysinfo.cc
View file @
e1208321
...
@@ -490,17 +490,19 @@ int GetNumCPUs() {
...
@@ -490,17 +490,19 @@ int GetNumCPUs() {
return
-
1
;
return
-
1
;
}
}
const
std
::
string
Key
=
"processor"
;
const
std
::
string
Key
=
"processor"
;
std
::
string
ln
;
std
::
string
ln
=
""
;
while
(
std
::
getline
(
f
,
ln
))
{
while
(
std
::
getline
(
f
,
ln
))
{
if
(
ln
.
empty
())
continue
;
if
(
ln
.
empty
())
continue
;
size_t
SplitI
dx
=
ln
.
find
(
':'
);
size_t
split_i
dx
=
ln
.
find
(
':'
);
std
::
string
value
;
std
::
string
value
;
#if defined(__s390__)
#if defined(__s390__)
// s390 has another format in /proc/cpuinfo
// s390 has another format in /proc/cpuinfo
// it needs to be parsed differently
// it needs to be parsed differently
if
(
SplitIdx
!=
std
::
string
::
npos
)
value
=
ln
.
substr
(
Key
.
size
()
+
1
,
SplitIdx
-
Key
.
size
()
-
1
);
if
(
split_idx
!=
std
::
string
::
npos
)
value
=
ln
.
substr
(
Key
.
size
()
+
1
,
split_idx
-
Key
.
size
()
-
1
);
#else
#else
if
(
SplitIdx
!=
std
::
string
::
npos
)
value
=
ln
.
substr
(
SplitIdx
+
1
);
if
(
split_idx
!=
std
::
string
::
npos
)
value
=
ln
.
substr
(
split_idx
+
1
);
#endif
#endif
if
(
ln
.
size
()
>=
Key
.
size
()
&&
ln
.
compare
(
0
,
Key
.
size
(),
Key
)
==
0
)
{
if
(
ln
.
size
()
>=
Key
.
size
()
&&
ln
.
compare
(
0
,
Key
.
size
(),
Key
)
==
0
)
{
NumCPUs
++
;
NumCPUs
++
;
...
@@ -581,9 +583,9 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
...
@@ -581,9 +583,9 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
std
::
string
ln
;
std
::
string
ln
;
while
(
std
::
getline
(
f
,
ln
))
{
while
(
std
::
getline
(
f
,
ln
))
{
if
(
ln
.
empty
())
continue
;
if
(
ln
.
empty
())
continue
;
size_t
SplitI
dx
=
ln
.
find
(
':'
);
size_t
split_i
dx
=
ln
.
find
(
':'
);
std
::
string
value
;
std
::
string
value
;
if
(
SplitIdx
!=
std
::
string
::
npos
)
value
=
ln
.
substr
(
SplitI
dx
+
1
);
if
(
split_idx
!=
std
::
string
::
npos
)
value
=
ln
.
substr
(
split_i
dx
+
1
);
// When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
// When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
// accept positive values. Some environments (virtual machines) report zero,
// accept positive values. Some environments (virtual machines) report zero,
// which would cause infinite looping in WallTime_Init.
// which would cause infinite looping in WallTime_Init.
...
@@ -614,7 +616,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
...
@@ -614,7 +616,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
if
(
bogo_clock
>=
0.0
)
return
bogo_clock
;
if
(
bogo_clock
>=
0.0
)
return
bogo_clock
;
#elif defined BENCHMARK_HAS_SYSCTL
#elif defined BENCHMARK_HAS_SYSCTL
constexpr
auto
*
FreqS
tr
=
constexpr
auto
*
freq_s
tr
=
#if defined(BENCHMARK_OS_FREEBSD) || defined(BENCHMARK_OS_NETBSD)
#if defined(BENCHMARK_OS_FREEBSD) || defined(BENCHMARK_OS_NETBSD)
"machdep.tsc_freq"
;
"machdep.tsc_freq"
;
#elif defined BENCHMARK_OS_OPENBSD
#elif defined BENCHMARK_OS_OPENBSD
...
@@ -626,12 +628,12 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
...
@@ -626,12 +628,12 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
#endif
#endif
unsigned
long
long
hz
=
0
;
unsigned
long
long
hz
=
0
;
#if defined BENCHMARK_OS_OPENBSD
#if defined BENCHMARK_OS_OPENBSD
if
(
GetSysctl
(
FreqS
tr
,
&
hz
))
return
hz
*
1000000
;
if
(
GetSysctl
(
freq_s
tr
,
&
hz
))
return
hz
*
1000000
;
#else
#else
if
(
GetSysctl
(
FreqS
tr
,
&
hz
))
return
hz
;
if
(
GetSysctl
(
freq_s
tr
,
&
hz
))
return
hz
;
#endif
#endif
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
FreqS
tr
,
strerror
(
errno
));
freq_s
tr
,
strerror
(
errno
));
#elif defined BENCHMARK_OS_WINDOWS
#elif defined BENCHMARK_OS_WINDOWS
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment