mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Throw an exception when trying to parse a negative number as an unsigned.
Fixing issue 859.
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
## HEAD ##
|
## HEAD ##
|
||||||
|
|
||||||
_none_
|
* Throws an exception when trying to parse a negative number as an unsigned integer.
|
||||||
|
|
||||||
## 0.6.0 ##
|
## 0.6.0 ##
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "yaml-cpp/binary.h"
|
#include "yaml-cpp/binary.h"
|
||||||
#include "yaml-cpp/node/impl.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(); \
|
const std::string& input = node.Scalar(); \
|
||||||
std::stringstream stream(input); \
|
std::stringstream stream(input); \
|
||||||
stream.unsetf(std::ios::dec); \
|
stream.unsetf(std::ios::dec); \
|
||||||
|
if ((stream.peek() == '-') && std::is_unsigned<type>::value) { \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { \
|
if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
|
@@ -32,6 +32,11 @@ TEST(LoadNodeTest, NumericConversion) {
|
|||||||
EXPECT_EQ(-std::numeric_limits<float>::infinity(), node[4].as<float>());
|
EXPECT_EQ(-std::numeric_limits<float>::infinity(), node[4].as<float>());
|
||||||
EXPECT_EQ(21, node[5].as<int>());
|
EXPECT_EQ(21, node[5].as<int>());
|
||||||
EXPECT_EQ(13, node[6].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) {
|
TEST(LoadNodeTest, Binary) {
|
||||||
|
Reference in New Issue
Block a user