Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
UERANSIM
Commits
e60b4cb9
Commit
e60b4cb9
authored
Jul 01, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Octal literal fix in YAML parsing
parent
8f55d2c9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
9 deletions
+19
-9
src/utils/yaml_utils.cpp
src/utils/yaml_utils.cpp
+19
-9
No files found.
src/utils/yaml_utils.cpp
View file @
e60b4cb9
...
...
@@ -9,6 +9,7 @@
#include "yaml_utils.hpp"
#include "common.hpp"
#include <cctype>
#include <stdexcept>
#include <yaml-cpp/yaml.h>
...
...
@@ -16,6 +17,19 @@
namespace
yaml
{
static
YAML
::
Node
OctalFix
(
const
YAML
::
Node
&
node
)
{
auto
s
=
node
.
as
<
std
::
string
>
();
if
(
!
std
::
all_of
(
s
.
begin
(),
s
.
end
(),
::
isdigit
))
return
node
;
if
(
!
s
.
empty
()
&&
s
[
0
]
!=
'0'
)
return
node
;
s
.
erase
(
0
,
std
::
min
(
s
.
find_first_not_of
(
'0'
),
s
.
size
()
-
1
));
return
YAML
::
Node
{
s
};
}
[[
noreturn
]]
void
FieldError
(
const
std
::
string
&
name
,
const
std
::
string
&
error
)
{
throw
std
::
runtime_error
(
"Field '"
+
name
+
"' "
+
error
+
"."
);
...
...
@@ -40,12 +54,8 @@ void AssertHasFields(const YAML::Node &node, const std::vector<std::string> &fie
int
GetInt32
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
{
auto
nodeValue
=
node
[
name
].
Scalar
();
nodeValue
.
erase
(
0
,
std
::
min
(
nodeValue
.
find_first_not_of
(
'0'
),
nodeValue
.
size
()
-
1
));
YAML
::
Node
modifiedNode
;
modifiedNode
[
name
]
=
nodeValue
;
AssertHasInt32
(
modifiedNode
,
name
);
return
modifiedNode
[
name
].
as
<
int
>
();
AssertHasInt32
(
node
,
name
);
return
OctalFix
(
node
[
name
]).
as
<
int
>
();
}
int
GetInt32
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
,
std
::
optional
<
int
>
minValue
,
std
::
optional
<
int
>
maxValue
)
...
...
@@ -63,7 +73,7 @@ void AssertHasInt32(const YAML::Node &node, const std::string &name)
AssertHasField
(
node
,
name
);
try
{
node
[
name
]
.
as
<
int
>
();
OctalFix
(
node
[
name
])
.
as
<
int
>
();
}
catch
(
const
std
::
runtime_error
&
e
)
{
...
...
@@ -106,7 +116,7 @@ void AssertHasInt64(const YAML::Node &node, const std::string &name)
AssertHasField
(
node
,
name
);
try
{
node
[
name
]
.
as
<
int64_t
>
();
OctalFix
(
node
[
name
])
.
as
<
int64_t
>
();
}
catch
(
const
std
::
runtime_error
&
e
)
{
...
...
@@ -117,7 +127,7 @@ void AssertHasInt64(const YAML::Node &node, const std::string &name)
int64_t
GetInt64
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
)
{
AssertHasInt64
(
node
,
name
);
return
node
[
name
]
.
as
<
int64_t
>
();
return
OctalFix
(
node
[
name
])
.
as
<
int64_t
>
();
}
int64_t
GetInt64
(
const
YAML
::
Node
&
node
,
const
std
::
string
&
name
,
std
::
optional
<
int64_t
>
minValue
,
...
...
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