Throw an exception when trying to parse a negative number as an unsigned.

Fixing issue 859.
This commit is contained in:
Chen
2020-05-20 00:48:22 +08:00
committed by GitHub
parent 4b98aedc16
commit d9c35b6079
3 changed files with 10 additions and 1 deletions

View File

@@ -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; \
} \