Loading src/html.cpp +16 −2 Original line number Diff line number Diff line Loading @@ -186,7 +186,15 @@ namespace libhtmlpp { }; libhtmlpp::HtmlString::HtmlString(char str) : HtmlString(){ _Data.push_back(str); // Route through the member push_back() rather than pushing onto _Data // directly -- that's the one place the trailing '\0' sentinel (see // size()'s doc comment) and the NUL-guard are maintained. Pushing raw // left _Data without a sentinel at all, so c_str() returned a // one-element buffer with no NUL terminator -- undefined behavior for // any caller that treats it as a C string -- and length() (before it // started delegating to size()) silently reported 0 for a real // 1-character string. push_back(str); } libhtmlpp::HtmlString::HtmlString(const std::string& str) : HtmlString(){ Loading Loading @@ -330,7 +338,13 @@ const char* libhtmlpp::HtmlString::operator*(){ } size_t libhtmlpp::HtmlString::length() const{ return _Data.empty() ? 0 : (_Data.size() - 1); // Pure synonym for size() (matching std::string's own size()/length() // convention) -- delegate instead of duplicating the sentinel-aware // logic a second time, which is what let this drift out of sync with // size() in the first place (this used to unconditionally subtract 1, // silently under-counting by one byte -- and never NUL-guarding -- // whenever the trailing '\0' sentinel wasn't actually present). return size(); } size_t libhtmlpp::HtmlString::size() const{ Loading Loading
src/html.cpp +16 −2 Original line number Diff line number Diff line Loading @@ -186,7 +186,15 @@ namespace libhtmlpp { }; libhtmlpp::HtmlString::HtmlString(char str) : HtmlString(){ _Data.push_back(str); // Route through the member push_back() rather than pushing onto _Data // directly -- that's the one place the trailing '\0' sentinel (see // size()'s doc comment) and the NUL-guard are maintained. Pushing raw // left _Data without a sentinel at all, so c_str() returned a // one-element buffer with no NUL terminator -- undefined behavior for // any caller that treats it as a C string -- and length() (before it // started delegating to size()) silently reported 0 for a real // 1-character string. push_back(str); } libhtmlpp::HtmlString::HtmlString(const std::string& str) : HtmlString(){ Loading Loading @@ -330,7 +338,13 @@ const char* libhtmlpp::HtmlString::operator*(){ } size_t libhtmlpp::HtmlString::length() const{ return _Data.empty() ? 0 : (_Data.size() - 1); // Pure synonym for size() (matching std::string's own size()/length() // convention) -- delegate instead of duplicating the sentinel-aware // logic a second time, which is what let this drift out of sync with // size() in the first place (this used to unconditionally subtract 1, // silently under-counting by one byte -- and never NUL-guarding -- // whenever the trailing '\0' sentinel wasn't actually present). return size(); } size_t libhtmlpp::HtmlString::size() const{ Loading