From d24a188d4c6862fdbe8429df91e67f6dc8a40db8 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 24 Dec 2018 15:06:26 +0900 Subject: [PATCH] fix the error while reading BOM. remove possible UB because of the use-after-move. --- toml/parser.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 882a49c..ab309fb 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -1472,10 +1472,10 @@ inline table parse(std::istream& is, std::string fname = "unknown file") // be compared to char. However, since we are always out of luck, we need to // check our chars are equivalent to BOM. To do this, first we need to // convert char to unsigned char to guarantee the comparability. - if(letters.size() >= 3) + if(loc.source()->size() >= 3) { std::array BOM; - std::memcpy(BOM.data(), letters.data(), 3); + std::memcpy(BOM.data(), loc.source()->data(), 3); if(BOM[0] == 0xEF && BOM[1] == 0xBB && BOM[2] == 0xBF) { loc.iter() += 3; // BOM found. skip.