aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-01-02 14:12:54 -0500
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:05 -0500
commit155fceabe7070b6610d577734734d038d097b088 (patch)
tree5bbbf327a00c2637f85f006c4b429ecc3b3cb1a3
parent1159aea45d9bc4ade2e82856be403d58e050f32d (diff)
downloadserd-155fceabe7070b6610d577734734d038d097b088.tar.gz
serd-155fceabe7070b6610d577734734d038d097b088.tar.bz2
serd-155fceabe7070b6610d577734734d038d097b088.zip
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.
-rw-r--r--src/byte_sink.c11
-rw-r--r--src/byte_source.c8
-rw-r--r--src/canon.c3
-rw-r--r--src/caret.c7
-rw-r--r--src/cursor.c4
-rw-r--r--src/describe.c2
-rw-r--r--src/env.c7
-rw-r--r--src/filter.c3
-rw-r--r--src/inserter.c3
-rw-r--r--src/log.c21
-rw-r--r--src/model.c38
-rw-r--r--src/node.c26
-rw-r--r--src/node_syntax.c7
-rw-r--r--src/nodes.c4
-rw-r--r--src/reader.c16
-rw-r--r--src/sink.c16
-rw-r--r--src/statement.c8
-rw-r--r--src/syntax.c6
-rw-r--r--src/system.c3
-rw-r--r--src/uri.c10
-rw-r--r--src/world.c4
-rw-r--r--src/writer.c18
22 files changed, 223 insertions, 2 deletions
diff --git a/src/byte_sink.c b/src/byte_sink.c
index e93e5a07..42d12f7b 100644
--- a/src/byte_sink.c
+++ b/src/byte_sink.c
@@ -21,6 +21,7 @@
#include "serd/serd.h"
+#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -32,6 +33,8 @@
SerdByteSink*
serd_byte_sink_new_buffer(SerdBuffer* const buffer)
{
+ assert(buffer);
+
SerdByteSink* sink = (SerdByteSink*)calloc(1, sizeof(SerdByteSink));
sink->write_func = serd_buffer_sink;
@@ -65,6 +68,8 @@ serd_byte_sink_new_internal(const SerdWriteFunc write_func,
SerdByteSink*
serd_byte_sink_new_filename(const char* const path, const size_t block_size)
{
+ assert(path);
+
if (!block_size) {
return NULL;
}
@@ -87,6 +92,8 @@ serd_byte_sink_new_function(const SerdWriteFunc write_func,
void* const stream,
const size_t block_size)
{
+ assert(write_func);
+
return block_size ? serd_byte_sink_new_internal(
write_func, stream, block_size, TO_FUNCTION)
: NULL;
@@ -95,6 +102,8 @@ serd_byte_sink_new_function(const SerdWriteFunc write_func,
void
serd_byte_sink_flush(SerdByteSink* sink)
{
+ assert(sink);
+
if (sink->block_size > 1 && sink->size > 0) {
sink->write_func(sink->buf, 1, sink->size, sink->stream);
sink->size = 0;
@@ -104,6 +113,8 @@ serd_byte_sink_flush(SerdByteSink* sink)
SerdStatus
serd_byte_sink_close(SerdByteSink* sink)
{
+ assert(sink);
+
serd_byte_sink_flush(sink);
if (sink->type == TO_FILENAME && sink->stream) {
diff --git a/src/byte_source.c b/src/byte_source.c
index ef6bf3bb..c0cb6413 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -28,6 +28,7 @@
# include <fcntl.h>
#endif
+#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -67,6 +68,9 @@ serd_byte_source_new_function(const SerdReadFunc read_func,
const SerdNode* const name,
const size_t page_size)
{
+ assert(read_func);
+ assert(error_func);
+
if (!page_size) {
return NULL;
}
@@ -114,6 +118,8 @@ is_directory(const char* const path)
SerdByteSource*
serd_byte_source_new_filename(const char* const path, const size_t page_size)
{
+ assert(path);
+
if (page_size == 0 || is_directory(path)) {
return NULL;
}
@@ -158,6 +164,8 @@ SerdByteSource*
serd_byte_source_new_string(const char* const string,
const SerdNode* const name)
{
+ assert(string);
+
SerdByteSource* source = (SerdByteSource*)calloc(1, sizeof(SerdByteSource));
source->page_size = 1;
diff --git a/src/canon.c b/src/canon.c
index 84d20d0c..67cf30bf 100644
--- a/src/canon.c
+++ b/src/canon.c
@@ -23,6 +23,7 @@
#include "exess/exess.h"
#include "serd/serd.h"
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -182,6 +183,8 @@ serd_canon_new(const SerdWorld* const world,
const SerdSink* const target,
const SerdCanonFlags flags)
{
+ assert(target);
+
SerdCanonData* const data = (SerdCanonData*)calloc(1, sizeof(SerdCanonData));
data->world = world;
diff --git a/src/caret.c b/src/caret.c
index 2fe92f94..b6911468 100644
--- a/src/caret.c
+++ b/src/caret.c
@@ -16,6 +16,7 @@
#include "caret.h"
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -23,6 +24,8 @@
SerdCaret*
serd_caret_new(const SerdNode* name, unsigned line, unsigned col)
{
+ assert(name);
+
SerdCaret* caret = (SerdCaret*)malloc(sizeof(SerdCaret));
caret->file = name;
@@ -59,17 +62,21 @@ serd_caret_equals(const SerdCaret* l, const SerdCaret* r)
const SerdNode*
serd_caret_name(const SerdCaret* caret)
{
+ assert(caret);
+ assert(caret->file);
return caret->file;
}
unsigned
serd_caret_line(const SerdCaret* caret)
{
+ assert(caret);
return caret->line;
}
unsigned
serd_caret_column(const SerdCaret* caret)
{
+ assert(caret);
return caret->col;
}
diff --git a/src/cursor.c b/src/cursor.c
index d57da866..4213476e 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -146,6 +146,8 @@ serd_cursor_copy(const SerdCursor* const cursor)
const SerdStatement*
serd_cursor_get(const SerdCursor* const cursor)
{
+ assert(cursor);
+
return ((!zix_btree_iter_is_end(cursor->iter) && check_version(cursor))
? (const SerdStatement*)zix_btree_get(cursor->iter)
: NULL);
@@ -182,6 +184,8 @@ serd_cursor_scan_next(SerdCursor* const cursor)
SerdStatus
serd_cursor_advance(SerdCursor* const cursor)
{
+ assert(cursor);
+
if (zix_btree_iter_is_end(cursor->iter) || !check_version(cursor)) {
return SERD_ERR_BAD_CURSOR;
}
diff --git a/src/describe.c b/src/describe.c
index 5ddbf7d0..9bd9d3ae 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -243,6 +243,8 @@ serd_describe_range(const SerdCursor* const range,
const SerdSink* sink,
const SerdDescribeFlags flags)
{
+ assert(sink);
+
SerdStatus st = SERD_SUCCESS;
if (serd_cursor_is_end(range)) {
diff --git a/src/env.c b/src/env.c
index 66698c12..0fd603a9 100644
--- a/src/env.c
+++ b/src/env.c
@@ -130,6 +130,8 @@ serd_env_base_uri(const SerdEnv* const env)
SerdStatus
serd_env_set_base_uri(SerdEnv* const env, const SerdStringView uri)
{
+ assert(env);
+
if (!uri.len) {
serd_nodes_deref(env->nodes, env->base_uri_node);
env->base_uri_node = NULL;
@@ -195,6 +197,8 @@ serd_env_set_prefix(SerdEnv* const env,
const SerdStringView name,
const SerdStringView uri)
{
+ assert(env);
+
if (serd_uri_string_has_scheme(uri.buf)) {
// Set prefix to absolute URI
serd_env_add(env, name, serd_nodes_uri(env->nodes, uri));
@@ -327,6 +331,9 @@ serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node)
void
serd_env_write_prefixes(const SerdEnv* const env, const SerdSink* const sink)
{
+ assert(env);
+ assert(sink);
+
for (size_t i = 0; i < env->n_prefixes; ++i) {
serd_sink_write_prefix(sink, env->prefixes[i].name, env->prefixes[i].uri);
}
diff --git a/src/filter.c b/src/filter.c
index 6d5e5a04..e5e8fa29 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -16,6 +16,7 @@
#include "serd/serd.h"
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -76,6 +77,8 @@ serd_filter_new(const SerdSink* const target,
const SerdNode* const graph,
const bool inclusive)
{
+ assert(target);
+
SerdFilterData* const data =
(SerdFilterData*)calloc(1, sizeof(SerdFilterData));
diff --git a/src/inserter.c b/src/inserter.c
index f5fd6ef1..100fc23a 100644
--- a/src/inserter.c
+++ b/src/inserter.c
@@ -19,6 +19,7 @@
#include "serd/serd.h"
+#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -109,6 +110,8 @@ serd_inserter_on_event(SerdInserterData* const data,
SerdSink*
serd_inserter_new(SerdModel* const model, const SerdNode* const default_graph)
{
+ assert(model);
+
SerdInserterData* const data =
(SerdInserterData*)calloc(1, sizeof(SerdInserterData));
diff --git a/src/log.c b/src/log.c
index 23db44f9..16c62860 100644
--- a/src/log.c
+++ b/src/log.c
@@ -18,6 +18,7 @@
#include "serd/serd.h"
+#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
@@ -106,6 +107,8 @@ serd_set_log_func(SerdWorld* const world,
const SerdLogFunc log_func,
void* const handle)
{
+ assert(world);
+
world->log_func = log_func;
world->log_handle = handle;
}
@@ -118,6 +121,9 @@ serd_vxlogf(const SerdWorld* const world,
const char* const fmt,
va_list args)
{
+ assert(world);
+ assert(fmt);
+
if (world->log_func) {
char message[512] = {0};
const int r = vsnprintf(message, sizeof(message), fmt, args);
@@ -165,6 +171,9 @@ serd_xlogf(const SerdWorld* const world,
const char* const fmt,
...)
{
+ assert(world);
+ assert(fmt);
+
va_list args;
va_start(args, fmt);
@@ -180,6 +189,9 @@ serd_vlogf(const SerdWorld* const world,
const char* const fmt,
va_list args)
{
+ assert(world);
+ assert(fmt);
+
return serd_vxlogf(world, level, 0u, NULL, fmt, args);
}
@@ -189,6 +201,9 @@ serd_logf(const SerdWorld* const world,
const char* const fmt,
...)
{
+ assert(world);
+ assert(fmt);
+
va_list args;
va_start(args, fmt);
@@ -205,6 +220,9 @@ serd_vlogf_at(const SerdWorld* SERD_NONNULL world,
const char* SERD_NONNULL fmt,
va_list args)
{
+ assert(world);
+ assert(fmt);
+
if (!caret) {
return serd_vxlogf(world, level, 0u, NULL, fmt, args);
}
@@ -230,6 +248,9 @@ serd_logf_at(const SerdWorld* SERD_NONNULL world,
const char* SERD_NONNULL fmt,
...)
{
+ assert(world);
+ assert(fmt);
+
va_list args;
va_start(args, fmt);
diff --git a/src/model.c b/src/model.c
index 0485b509..e6033278 100644
--- a/src/model.c
+++ b/src/model.c
@@ -64,6 +64,8 @@ serd_model_pattern_comparator(const SerdModel* const model,
SerdStatus
serd_model_add_index(SerdModel* const model, const SerdStatementOrder order)
{
+ assert(model);
+
if (model->indices[order]) {
return SERD_FAILURE;
}
@@ -91,6 +93,8 @@ serd_model_add_index(SerdModel* const model, const SerdStatementOrder order)
SerdStatus
serd_model_drop_index(SerdModel* const model, const SerdStatementOrder order)
{
+ assert(model);
+
if (!model->indices[order]) {
return SERD_FAILURE;
}
@@ -109,6 +113,8 @@ serd_model_new(SerdWorld* const world,
const SerdStatementOrder default_order,
const SerdModelFlags flags)
{
+ assert(world);
+
SerdModel* model = (SerdModel*)calloc(1, sizeof(struct SerdModelImpl));
model->world = world;
@@ -131,6 +137,8 @@ serd_model_new(SerdWorld* const world,
SerdModel*
serd_model_copy(const SerdModel* const model)
{
+ assert(model);
+
SerdModel* copy =
serd_model_new(model->world, model->default_order, model->flags);
@@ -261,36 +269,42 @@ serd_model_free(SerdModel* const model)
SerdWorld*
serd_model_world(SerdModel* const model)
{
+ assert(model);
return model->world;
}
const SerdNodes*
serd_model_nodes(const SerdModel* const model)
{
+ assert(model);
return model->nodes;
}
SerdStatementOrder
serd_model_default_order(const SerdModel* const model)
{
+ assert(model);
return model->default_order;
}
SerdModelFlags
serd_model_flags(const SerdModel* const model)
{
+ assert(model);
return model->flags;
}
size_t
serd_model_size(const SerdModel* const model)
{
+ assert(model);
return zix_btree_size(model->indices[model->default_order]);
}
bool
serd_model_empty(const SerdModel* const model)
{
+ assert(model);
return serd_model_size(model) == 0;
}
@@ -298,6 +312,8 @@ SerdCursor*
serd_model_begin_ordered(const SerdModel* const model,
const SerdStatementOrder order)
{
+ assert(model);
+
const SerdCursor cursor = make_begin_cursor(model, order);
return serd_cursor_copy(&cursor);
@@ -306,12 +322,14 @@ serd_model_begin_ordered(const SerdModel* const model,
SerdCursor*
serd_model_begin(const SerdModel* const model)
{
+ assert(model);
return serd_model_begin_ordered(model, model->default_order);
}
const SerdCursor*
serd_model_end(const SerdModel* const model)
{
+ assert(model);
return &model->end;
}
@@ -495,6 +513,8 @@ serd_model_find(const SerdModel* const model,
const SerdNode* const o,
const SerdNode* const g)
{
+ assert(model);
+
const SerdCursor cursor = serd_model_search(model, s, p, o, g);
return zix_btree_iter_is_end(cursor.iter) ? NULL : serd_cursor_copy(&cursor);
@@ -507,6 +527,8 @@ serd_model_get(const SerdModel* const model,
const SerdNode* const o,
const SerdNode* const g)
{
+ assert(model);
+
const SerdStatement* const statement =
serd_model_get_statement(model, s, p, o, g);
@@ -525,6 +547,8 @@ serd_model_get_statement(const SerdModel* const model,
const SerdNode* const o,
const SerdNode* const g)
{
+ assert(model);
+
if ((bool)s + (bool)p + (bool)o != 2 &&
(bool)s + (bool)p + (bool)o + (bool)g != 3) {
return NULL;
@@ -542,6 +566,8 @@ serd_model_count(const SerdModel* const model,
const SerdNode* const o,
const SerdNode* const g)
{
+ assert(model);
+
SerdCursor i = serd_model_search(model, s, p, o, g);
size_t count = 0;
@@ -559,6 +585,8 @@ serd_model_ask(const SerdModel* const model,
const SerdNode* const o,
const SerdNode* const g)
{
+ assert(model);
+
const SerdCursor c = serd_model_search(model, s, p, o, g);
return !serd_cursor_is_end(&c);
@@ -587,6 +615,8 @@ serd_model_add_with_caret(SerdModel* const model,
const SerdNode* const g,
const SerdCaret* const caret)
{
+ assert(model);
+
SerdStatement* const statement = serd_statement_new(s, p, o, g, NULL);
if (!statement) {
return SERD_ERR_UNKNOWN;
@@ -663,6 +693,9 @@ serd_model_insert_statements(SerdModel* const model, SerdCursor* const range)
SerdStatus
serd_model_erase(SerdModel* const model, SerdCursor* const cursor)
{
+ assert(model);
+ assert(cursor);
+
const SerdStatement* statement = serd_cursor_get(cursor);
SerdStatement* removed = NULL;
ZixStatus zst = ZIX_STATUS_SUCCESS;
@@ -706,6 +739,9 @@ serd_model_erase(SerdModel* const model, SerdCursor* const cursor)
SerdStatus
serd_model_erase_statements(SerdModel* const model, SerdCursor* const range)
{
+ assert(model);
+ assert(range);
+
SerdStatus st = SERD_SUCCESS;
while (!st && !serd_cursor_is_end(range)) {
@@ -718,6 +754,8 @@ serd_model_erase_statements(SerdModel* const model, SerdCursor* const range)
SerdStatus
serd_model_clear(SerdModel* const model)
{
+ assert(model);
+
SerdCursor i = make_begin_cursor(model, model->default_order);
while (!serd_cursor_is_end(&i)) {
diff --git a/src/node.c b/src/node.c
index 6958ea5e..550fa732 100644
--- a/src/node.c
+++ b/src/node.c
@@ -546,6 +546,8 @@ serd_node_get_value_as(const SerdNode* const node,
bool
serd_get_boolean(const SerdNode* const node)
{
+ assert(node);
+
bool value = false;
serd_node_get_value_as(node, EXESS_BOOLEAN, sizeof(value), &value);
@@ -555,6 +557,8 @@ serd_get_boolean(const SerdNode* const node)
double
serd_get_double(const SerdNode* const node)
{
+ assert(node);
+
double value = (double)NAN; // NOLINT(google-readability-casting)
serd_node_get_value_as(node, EXESS_DOUBLE, sizeof(value), &value);
@@ -564,6 +568,8 @@ serd_get_double(const SerdNode* const node)
float
serd_get_float(const SerdNode* const node)
{
+ assert(node);
+
float value = (float)NAN; // NOLINT(google-readability-casting)
serd_node_get_value_as(node, EXESS_FLOAT, sizeof(value), &value);
@@ -573,6 +579,8 @@ serd_get_float(const SerdNode* const node)
int64_t
serd_get_integer(const SerdNode* const node)
{
+ assert(node);
+
int64_t value = 0;
serd_node_get_value_as(node, EXESS_LONG, sizeof(value), &value);
@@ -865,24 +873,32 @@ serd_new_base64(const void* buf, size_t size, const SerdStringView datatype)
SerdNodeType
serd_node_type(const SerdNode* const node)
{
+ assert(node);
+
return node->type;
}
const char*
serd_node_string(const SerdNode* const node)
{
+ assert(node);
+
return (const char*)(node + 1);
}
size_t
serd_node_length(const SerdNode* const node)
{
+ assert(node);
+
return node->length;
}
SerdStringView
serd_node_string_view(const SerdNode* const node)
{
+ assert(node);
+
const SerdStringView r = {(const char*)(node + 1), node->length};
return r;
@@ -891,6 +907,8 @@ serd_node_string_view(const SerdNode* const node)
SerdURIView
serd_node_uri_view(const SerdNode* const node)
{
+ assert(node);
+
return (node->type == SERD_URI) ? serd_parse_uri(serd_node_string(node))
: SERD_URI_NULL;
}
@@ -898,7 +916,9 @@ serd_node_uri_view(const SerdNode* const node)
const SerdNode*
serd_node_datatype(const SerdNode* const node)
{
- if (!node || !(node->flags & SERD_HAS_DATATYPE)) {
+ assert(node);
+
+ if (!(node->flags & SERD_HAS_DATATYPE)) {
return NULL;
}
@@ -910,7 +930,9 @@ serd_node_datatype(const SerdNode* const node)
const SerdNode*
serd_node_language(const SerdNode* const node)
{
- if (!node || !(node->flags & SERD_HAS_LANGUAGE)) {
+ assert(node);
+
+ if (!(node->flags & SERD_HAS_LANGUAGE)) {
return NULL;
}
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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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 <http://www.w3.org/2000/01/rdf-schema#object>";
@@ -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);
}
diff --git a/src/nodes.c b/src/nodes.c
index a7d0ab2b..5c6492e4 100644
--- a/src/nodes.c
+++ b/src/nodes.c
@@ -225,6 +225,8 @@ serd_nodes_free(SerdNodes* nodes)
size_t
serd_nodes_size(const SerdNodes* nodes)
{
+ assert(nodes);
+
return zix_hash_size(nodes->hash);
}
@@ -257,6 +259,8 @@ serd_nodes_intern(SerdNodes* nodes, const SerdNode* node)
const SerdNode*
serd_nodes_get(const SerdNodes* const nodes, const SerdNode* const node)
{
+ assert(nodes);
+
if (!node) {
return NULL;
}
diff --git a/src/reader.c b/src/reader.c
index 91e61f72..7a640cc6 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -25,6 +25,7 @@
#include "statement.h"
#include "system.h"
+#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -194,6 +195,8 @@ read_statement(SerdReader* const reader)
SerdStatus
serd_reader_read_document(SerdReader* const reader)
{
+ assert(reader);
+
if (!reader->source) {
return SERD_ERR_BAD_CALL;
}
@@ -229,6 +232,10 @@ serd_reader_new(SerdWorld* const world,
const SerdSink* const sink,
const size_t stack_size)
{
+ assert(world);
+ assert(env);
+ assert(sink);
+
if (stack_size < 3 * sizeof(SerdNode) + 192 + serd_node_align) {
return NULL;
}
@@ -276,6 +283,8 @@ serd_reader_free(SerdReader* const reader)
void
serd_reader_add_blank_prefix(SerdReader* const reader, const char* const prefix)
{
+ assert(reader);
+
free(reader->bprefix);
reader->bprefix_len = 0;
reader->bprefix = NULL;
@@ -308,6 +317,9 @@ skip_bom(SerdReader* const me)
SerdStatus
serd_reader_start(SerdReader* const reader, SerdByteSource* const byte_source)
{
+ assert(reader);
+ assert(byte_source);
+
serd_reader_finish(reader);
reader->source = byte_source;
@@ -330,6 +342,8 @@ serd_reader_prepare(SerdReader* const reader)
SerdStatus
serd_reader_read_chunk(SerdReader* const reader)
{
+ assert(reader);
+
SerdStatus st = SERD_SUCCESS;
if (!reader->source) {
return SERD_ERR_BAD_CALL;
@@ -347,6 +361,8 @@ serd_reader_read_chunk(SerdReader* const reader)
SerdStatus
serd_reader_finish(SerdReader* const reader)
{
+ assert(reader);
+
reader->source = NULL;
return SERD_SUCCESS;
}
diff --git a/src/sink.c b/src/sink.c
index 4b7c6646..bd6f1193 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -52,12 +52,18 @@ serd_sink_free(SerdSink* sink)
SerdStatus
serd_sink_write_event(const SerdSink* sink, const SerdEvent* event)
{
+ assert(sink);
+ assert(event);
+
return sink->on_event ? sink->on_event(sink->handle, event) : SERD_SUCCESS;
}
SerdStatus
serd_sink_write_base(const SerdSink* sink, const SerdNode* uri)
{
+ assert(sink);
+ assert(uri);
+
const SerdBaseEvent ev = {SERD_BASE, uri};
return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev)
@@ -69,6 +75,10 @@ serd_sink_write_prefix(const SerdSink* sink,
const SerdNode* name,
const SerdNode* uri)
{
+ assert(sink);
+ assert(name);
+ assert(uri);
+
const SerdPrefixEvent ev = {SERD_PREFIX, name, uri};
return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev)
@@ -80,6 +90,9 @@ serd_sink_write_statement(const SerdSink* sink,
const SerdStatementFlags flags,
const SerdStatement* statement)
{
+ assert(sink);
+ assert(statement);
+
const SerdStatementEvent statement_ev = {SERD_STATEMENT, flags, statement};
SerdEvent ev = {SERD_STATEMENT};
ev.statement = statement_ev;
@@ -107,6 +120,9 @@ serd_sink_write(const SerdSink* sink,
SerdStatus
serd_sink_write_end(const SerdSink* sink, const SerdNode* node)
{
+ assert(sink);
+ assert(node);
+
const SerdEndEvent ev = {SERD_END, node};
return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev)
diff --git a/src/statement.c b/src/statement.c
index 7bb2486f..8ca0d8ee 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -97,36 +97,42 @@ serd_statement_free(SerdStatement* const statement)
const SerdNode*
serd_statement_node(const SerdStatement* const statement, const SerdField field)
{
+ assert(statement);
return statement->nodes[field];
}
const SerdNode*
serd_statement_subject(const SerdStatement* const statement)
{
+ assert(statement);
return statement->nodes[SERD_SUBJECT];
}
const SerdNode*
serd_statement_predicate(const SerdStatement* const statement)
{
+ assert(statement);
return statement->nodes[SERD_PREDICATE];
}
const SerdNode*
serd_statement_object(const SerdStatement* const statement)
{
+ assert(statement);
return statement->nodes[SERD_OBJECT];
}
const SerdNode*
serd_statement_graph(const SerdStatement* const statement)
{
+ assert(statement);
return statement->nodes[SERD_GRAPH];
}
const SerdCaret*
serd_statement_caret(const SerdStatement* const statement)
{
+ assert(statement);
return statement->caret;
}
@@ -147,6 +153,8 @@ serd_statement_matches(const SerdStatement* const statement,
const SerdNode* const object,
const SerdNode* const graph)
{
+ assert(statement);
+
return (serd_node_pattern_match(statement->nodes[0], subject) &&
serd_node_pattern_match(statement->nodes[1], predicate) &&
serd_node_pattern_match(statement->nodes[2], object) &&
diff --git a/src/syntax.c b/src/syntax.c
index 59453bca..ace55ce2 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -18,6 +18,7 @@
#include "serd/serd.h"
+#include <assert.h>
#include <stdbool.h>
#include <string.h>
@@ -38,17 +39,22 @@ static const Syntax syntaxes[] = {
SerdSyntax
serd_syntax_by_name(const char* const name)
{
+ assert(name);
+
for (const Syntax* s = syntaxes; s->name; ++s) {
if (!serd_strncasecmp(s->name, name, strlen(name))) {
return s->syntax;
}
}
+
return SERD_SYNTAX_EMPTY;
}
SerdSyntax
serd_guess_syntax(const char* const filename)
{
+ assert(filename);
+
const char* ext = strrchr(filename, '.');
if (ext) {
for (const Syntax* s = syntaxes; s->name; ++s) {
diff --git a/src/system.c b/src/system.c
index 61635591..cb6ceb6d 100644
--- a/src/system.c
+++ b/src/system.c
@@ -25,6 +25,7 @@
# include <windows.h>
#endif
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -92,6 +93,8 @@ serd_free_aligned(void* const ptr)
char*
serd_canonical_path(const char* const path)
{
+ assert(path);
+
#ifdef _WIN32
const DWORD size = GetFullPathName(path, 0, NULL, NULL);
if (size == 0) {
diff --git a/src/uri.c b/src/uri.c
index c66e28d7..1862c280 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -19,6 +19,7 @@
#include "serd/serd.h"
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,6 +28,8 @@
char*
serd_parse_file_uri(const char* const uri, char** const hostname)
{
+ assert(uri);
+
const char* path = uri;
if (hostname) {
*hostname = NULL;
@@ -79,6 +82,8 @@ serd_parse_file_uri(const char* const uri, char** const hostname)
bool
serd_uri_string_has_scheme(const char* const string)
{
+ assert(string);
+
if (is_alpha(string[0])) {
for (size_t i = 1; string[i]; ++i) {
if (!is_uri_scheme_char(string[i])) {
@@ -97,6 +102,8 @@ serd_uri_string_has_scheme(const char* const string)
SerdURIView
serd_parse_uri(const char* const string)
{
+ assert(string);
+
SerdURIView result = SERD_URI_NULL;
const char* ptr = string;
@@ -453,6 +460,9 @@ serd_write_uri(const SerdURIView uri,
const SerdWriteFunc sink,
void* const stream)
{
+ assert(sink);
+ assert(stream);
+
size_t len = 0;
if (uri.scheme.buf) {
diff --git a/src/world.c b/src/world.c
index 58efac90..39eeaec3 100644
--- a/src/world.c
+++ b/src/world.c
@@ -24,6 +24,7 @@
# include <unistd.h>
#endif
+#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -110,12 +111,15 @@ serd_world_free(SerdWorld* const world)
SerdNodes*
serd_world_nodes(SerdWorld* const world)
{
+ assert(world);
return world->nodes;
}
const SerdNode*
serd_world_get_blank(SerdWorld* const world)
{
+ assert(world);
+
char* buf = world->blank.string;
memset(buf, 0, BLANK_CHARS + 1);
diff --git a/src/writer.c b/src/writer.c
index 5416d144..e73533e7 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -1268,6 +1268,8 @@ serd_writer_write_node(SerdWriter* writer, const SerdNode* node)
SerdStatus
serd_writer_finish(SerdWriter* writer)
{
+ assert(writer);
+
SerdStatus st = SERD_SUCCESS;
if (ctx(writer, SERD_SUBJECT)) {
st = write_sep(writer, writer->context.flags, SEP_END_S);
@@ -1296,6 +1298,10 @@ serd_writer_new(SerdWorld* world,
const SerdEnv* env,
SerdByteSink* byte_sink)
{
+ assert(world);
+ assert(env);
+ assert(byte_sink);
+
const WriteContext context = WRITE_CONTEXT_NULL;
SerdWriter* writer = (SerdWriter*)calloc(1, sizeof(SerdWriter));
@@ -1321,6 +1327,8 @@ serd_writer_new(SerdWorld* world,
void
serd_writer_chop_blank_prefix(SerdWriter* writer, const char* prefix)
{
+ assert(writer);
+
free(writer->bprefix);
writer->bprefix_len = 0;
writer->bprefix = NULL;
@@ -1336,6 +1344,8 @@ serd_writer_chop_blank_prefix(SerdWriter* writer, const char* prefix)
SerdStatus
serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri)
{
+ assert(writer);
+
if (uri->type != SERD_URI) {
return SERD_ERR_BAD_ARG;
}
@@ -1362,6 +1372,8 @@ serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri)
SerdStatus
serd_writer_set_root_uri(SerdWriter* writer, const SerdNode* uri)
{
+ assert(writer);
+
serd_node_free(writer->root_node);
writer->root_node = NULL;
writer->root_uri = SERD_URI_NULL;
@@ -1421,6 +1433,7 @@ serd_writer_free(SerdWriter* writer)
const SerdSink*
serd_writer_sink(SerdWriter* writer)
{
+ assert(writer);
return &writer->iface;
}
@@ -1430,7 +1443,10 @@ serd_buffer_sink(const void* const buf,
const size_t nmemb,
void* const stream)
{
+ assert(buf);
assert(size == 1);
+ assert(stream);
+
(void)size;
SerdBuffer* buffer = (SerdBuffer*)stream;
@@ -1443,6 +1459,8 @@ serd_buffer_sink(const void* const buf,
char*
serd_buffer_sink_finish(SerdBuffer* const stream)
{
+ assert(stream);
+
serd_buffer_sink("", 1, 1, stream);
return (char*)stream->buf;
}