[pim/kdepim-addons] /: Check potential crash

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 718a82b0da4344652e9c73fcd050cdb70eea4fa1 by Laurent Montel.
Committed on 16/08/2026 at 15:14.
Pushed by mlaurent into branch 'master'.

Check potential crash

M  +6    -1    kmail/editorconvertertextplugins/markdown/markdownlib/markdownconverter.cpp
M  +6    -1    plugins/messageviewer/bodypartformatter/markdown/markdowndiscount.cpp

https://invent.kde.org/pim/kdepim-addons/-/commit/718a82b0da4344652e9c73fcd050cdb70eea4fa1

diff --git a/kmail/editorconvertertextplugins/markdown/markdownlib/markdownconverter.cpp b/kmail/editorconvertertextplugins/markdown/markdownlib/markdownconverter.cpp
index 8a33deffc..d756a4f0f 100644
--- a/kmail/editorconvertertextplugins/markdown/markdownlib/markdownconverter.cpp
+++ b/kmail/editorconvertertextplugins/markdown/markdownlib/markdownconverter.cpp
@@ -107,8 +107,13 @@ QString MarkdownConverter::convertTextToMarkdown(const QString &str)
     }
     mkd_free_flags(flags);
 #endif
-    char *htmlDocument;
+    char *htmlDocument = nullptr;
     const int size = mkd_document(markdownHandle, &htmlDocument);
+    if (size < 0 || !htmlDocument) {
+        qWarning() << "Failed to generate the Markdown document.";
+        mkd_cleanup(markdownHandle);
+        return {};
+    }
 
     const QString html = QString::fromUtf8(htmlDocument, size);
 
diff --git a/plugins/messageviewer/bodypartformatter/markdown/markdowndiscount.cpp b/plugins/messageviewer/bodypartformatter/markdown/markdowndiscount.cpp
index 98ecf93b8..958d741e4 100644
--- a/plugins/messageviewer/bodypartformatter/markdown/markdowndiscount.cpp
+++ b/plugins/messageviewer/bodypartformatter/markdown/markdowndiscount.cpp
@@ -48,8 +48,13 @@ QString MarkdownDiscount::toHtml() const
     mkd_free_flags(flags);
 #endif
 
-    char *htmlDocument;
+    char *htmlDocument = nullptr;
     const int size = mkd_document(markdownHandle, &htmlDocument);
+    if (size < 0 || !htmlDocument) {
+        qWarning() << "Failed to generate the Markdown document.";
+        mkd_cleanup(markdownHandle);
+        return {};
+    }
 
     const QString html = QString::fromUtf8(htmlDocument, size);
     mkd_cleanup(markdownHandle);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.