aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-02-06 12:59:11 +0100
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-02-06 13:14:57 +0100
commitd0e34c85f85510cb2ef591de29693b4cf8bdc65b (patch)
tree0be80ef1bd8cbe762eaaf59468b97396b63ac60c /src
parent480426a364f09e7992230b32f2941a09fb52d729 (diff)
libcmd/markdown: handle allocation errors in lowdown_term_rndr
We upgrade to lowdown 0.8.0 [1] which contains a fix/improvement to a behavior mentioned in this issue thread [2] where a big part of lowdown's API would just call exit(1) on allocation errors since that is a satisfying behavior for the lowdown binary. Now lowdown_term_rndr returns 0 if an allocation error occurred which we check for in libcmd/markdown.cc. Also the extern "C" { } wrapper around lowdown.h has been removed as it is not necessary. [1]: https://github.com/kristapsdz/lowdown/blob/6ca7c855a063d1c77ae0b89405047cc3913a74d8/versions.xml#L987-L1006 [2]: https://github.com/kristapsdz/lowdown/issues/45#issuecomment-756681153
Diffstat (limited to 'src')
-rw-r--r--src/libcmd/markdown.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libcmd/markdown.cc b/src/libcmd/markdown.cc
index 40788a42f..d25113d93 100644
--- a/src/libcmd/markdown.cc
+++ b/src/libcmd/markdown.cc
@@ -3,9 +3,7 @@
#include "finally.hh"
#include <sys/queue.h>
-extern "C" {
#include <lowdown.h>
-}
namespace nix {
@@ -42,7 +40,9 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
throw Error("cannot allocate Markdown output buffer");
Finally freeBuffer([&]() { lowdown_buf_free(buf); });
- lowdown_term_rndr(buf, nullptr, renderer, node);
+ int rndr_res = lowdown_term_rndr(buf, nullptr, renderer, node);
+ if (!rndr_res)
+ throw Error("allocation error while rendering Markdown");
return std::string(buf->data, buf->size);
}