Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
d9c35b60
Unverified
Commit
d9c35b60
authored
May 20, 2020
by
Chen
Committed by
GitHub
May 19, 2020
Browse files
Throw an exception when trying to parse a negative number as an unsigned.
Fixing issue 859.
parent
4b98aedc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
1 deletion
+10
-1
docs/Breaking-Changes.md
docs/Breaking-Changes.md
+1
-1
include/yaml-cpp/node/convert.h
include/yaml-cpp/node/convert.h
+4
-0
test/integration/load_node_test.cpp
test/integration/load_node_test.cpp
+5
-0
No files found.
docs/Breaking-Changes.md
View file @
d9c35b60
...
...
@@ -4,7 +4,7 @@
## HEAD ##
_none_
*
Throws an exception when trying to parse a negative number as an unsigned integer.
## 0.6.0 ##
...
...
include/yaml-cpp/node/convert.h
View file @
d9c35b60
...
...
@@ -15,6 +15,7 @@
#include <sstream>
#include <type_traits>
#include <vector>
#include <type_traits>
#include "yaml-cpp/binary.h"
#include "yaml-cpp/node/impl.h"
...
...
@@ -133,6 +134,9 @@ inner_encode(const T& rhs, std::stringstream& stream){
const std::string& input = node.Scalar(); \
std::stringstream stream(input); \
stream.unsetf(std::ios::dec); \
if ((stream.peek() == '-') && std::is_unsigned<type>::value) { \
return false; \
} \
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { \
return true; \
} \
...
...
test/integration/load_node_test.cpp
View file @
d9c35b60
...
...
@@ -32,6 +32,11 @@ TEST(LoadNodeTest, NumericConversion) {
EXPECT_EQ
(
-
std
::
numeric_limits
<
float
>::
infinity
(),
node
[
4
].
as
<
float
>
());
EXPECT_EQ
(
21
,
node
[
5
].
as
<
int
>
());
EXPECT_EQ
(
13
,
node
[
6
].
as
<
int
>
());
// Throw exception: convert a negative number to an unsigned number.
EXPECT_THROW
(
node
[
7
].
as
<
unsigned
>
(),
TypedBadConversion
<
unsigned
int
>
);
EXPECT_THROW
(
node
[
7
].
as
<
unsigned
short
>
(),
TypedBadConversion
<
unsigned
short
>
);
EXPECT_THROW
(
node
[
7
].
as
<
unsigned
long
>
(),
TypedBadConversion
<
unsigned
long
>
);
EXPECT_THROW
(
node
[
7
].
as
<
unsigned
long
long
>
(),
TypedBadConversion
<
unsigned
long
long
>
);
}
TEST
(
LoadNodeTest
,
Binary
)
{
...
...
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