From 93861f07dd9426e822520afdb2ca38dfa9719f41 Mon Sep 17 00:00:00 2001 From: alistair Date: Tue, 31 Aug 2021 12:53:38 +1000 Subject: [PATCH] handle missing language in highlight --- srchighlight.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/srchighlight.hpp b/srchighlight.hpp index 57da715..56970a5 100644 --- a/srchighlight.hpp +++ b/srchighlight.hpp @@ -209,7 +209,16 @@ class gnu_highlighter { const std::string &lang) { char *highlighted = syntect_to_html(lang.c_str(), "base16-ocean.light", program.c_str()); - return std::string(highlighted, highlighted + strlen(highlighted)); + + if (highlighted) { + auto res = std::string(highlighted, highlighted + strlen(highlighted)); + syntect_release_str(highlighted); + return res; + } else { + spdlog::warn("Failed to highlight code block, bad language? '{}'", lang); + return program; + } + //return oout.str(); }