Loading src/html.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -334,12 +334,22 @@ size_t libhtmlpp::HtmlString::length() const{ } size_t libhtmlpp::HtmlString::size() const{ // append()/push_back()/etc. maintain a trailing '\0' sentinel in _Data so // c_str() stays valid between calls (pop it, write new content, push it // back) — that byte is a private bookkeeping detail, not real content, // so it must not be counted here. Without this, every consumer that // trusts size()/str() to describe the actual string (e.g. building a // larger buffer by concatenating multiple HtmlString results) ends up // with a genuine embedded NUL baked into otherwise-clean text, which // then silently truncates any later strlen()-based use of that buffer. if (!_Data.empty() && _Data.back() == '\0') return _Data.size() - 1; return _Data.size(); } const std::string libhtmlpp::HtmlString::str() const{ if(_Data.data()) return std::string(_Data.begin(),_Data.end()); return std::string(_Data.begin(), _Data.begin() + static_cast<long>(size())); return ""; } Loading Loading
src/html.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -334,12 +334,22 @@ size_t libhtmlpp::HtmlString::length() const{ } size_t libhtmlpp::HtmlString::size() const{ // append()/push_back()/etc. maintain a trailing '\0' sentinel in _Data so // c_str() stays valid between calls (pop it, write new content, push it // back) — that byte is a private bookkeeping detail, not real content, // so it must not be counted here. Without this, every consumer that // trusts size()/str() to describe the actual string (e.g. building a // larger buffer by concatenating multiple HtmlString results) ends up // with a genuine embedded NUL baked into otherwise-clean text, which // then silently truncates any later strlen()-based use of that buffer. if (!_Data.empty() && _Data.back() == '\0') return _Data.size() - 1; return _Data.size(); } const std::string libhtmlpp::HtmlString::str() const{ if(_Data.data()) return std::string(_Data.begin(),_Data.end()); return std::string(_Data.begin(), _Data.begin() + static_cast<long>(size())); return ""; } Loading