From b30515bfeaf3f23ec6bb2427818dc3695fb14464 Mon Sep 17 00:00:00 2001
From: Sude <lgogdownloader@gmail.com>
Date: Thu, 22 Aug 2024 18:59:41 +0300
Subject: [PATCH] Check for errors in Util::htmlToXhtml

---
 src/util.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/util.cpp b/src/util.cpp
index a976825..2a5cc2a 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1028,7 +1028,15 @@ std::string Util::htmlToXhtml(const std::string& html)
     if ( rc >= 0 )
         rc = tidySaveBuffer(doc, &buffer);
 
-    xhtml = std::string((char*)buffer.bp, buffer.size);
+    if (rc >= 0)
+    {
+        if (buffer.size > 0)
+            xhtml = std::string((char*)buffer.bp, buffer.size);
+    }
+    else
+    {
+        std::cerr << "Severe error occured: " << std::string(strerror(rc)) << std::endl;
+    }
 
     tidyBufFree(&buffer);
     tidyRelease(doc);