Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/yaml-cpp/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class YAML_CPP_API Binary {
bool owned() const { return !m_unownedData; }
std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
const unsigned char *data() const {
return owned() ? &m_data[0] : m_unownedData;
return owned() ? m_data.data() : m_unownedData;
}

void swap(std::vector<unsigned char> &rhs) {
Expand Down
6 changes: 6 additions & 0 deletions test/binary_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ TEST(BinaryTest, DecodingTooShort) {
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_TRUE(result.empty());
}

TEST(BinaryTest, EmptyBinary) {
YAML::Binary b;
EXPECT_TRUE(b.size() == 0);
EXPECT_TRUE(b.data() == b.data()); // caused UB in the past
}