From 155fceabe7070b6610d577734734d038d097b088 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 2 Jan 2022 14:12:54 -0500 Subject: Add assertions for all non-null pointers in the public API Clang issues warnings at build time based on the SERD_NONNULL annotations, which is a much better approach in general. However, it does not cover cases where the API is being used with another compiler, or without a compiler that can statically check things at all (such as Python or other dynamic language bindings). In those situations, getting a clear assertion message is a lot less confusing than a random crash somewhere in serd, and it makes it clear that the bug is in the caller, so I think it's worth the tedious verbosity. --- src/node_syntax.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/node_syntax.c') diff --git a/src/node_syntax.c b/src/node_syntax.c index 626648f6..ff8c32d4 100644 --- a/src/node_syntax.c +++ b/src/node_syntax.c @@ -18,6 +18,7 @@ #include "serd/serd.h" +#include #include #include #include @@ -38,6 +39,8 @@ serd_node_from_syntax_in(const char* const str, const SerdSyntax syntax, SerdEnv* const env) { + assert(str); + static const char* const prelude = "_:s "; @@ -72,6 +75,8 @@ serd_node_from_syntax(const char* const str, const SerdSyntax syntax, SerdEnv* const env) { + assert(str); + if (env) { return serd_node_from_syntax_in(str, syntax, env); } @@ -110,6 +115,8 @@ serd_node_to_syntax(const SerdNode* const node, const SerdSyntax syntax, const SerdEnv* const env) { + assert(node); + if (env) { return serd_node_to_syntax_in(node, syntax, env); } -- cgit v1.2.1