diff --git a/src/html.cc b/src/html.cc
index f0c85a9..d0dfbe1 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -4150,7 +4150,7 @@ static const char *Html_get_attr2(DilloHtml *html,
}
if (tag_parsing_flags & HTML_LeftTrim)
- while (isspace(Buf.front()))
+ while (not Buf.empty() and isspace(Buf.front()))
Buf.erase( 0, 1 );
if (tag_parsing_flags & HTML_RightTrim)
while (Buf.size() && isspace( Buf.back() ))