diff options
author | David Robillard <d@drobilla.net> | 2022-01-02 14:12:54 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:05 -0500 |
commit | 155fceabe7070b6610d577734734d038d097b088 (patch) | |
tree | 5bbbf327a00c2637f85f006c4b429ecc3b3cb1a3 /src/uri.c | |
parent | 1159aea45d9bc4ade2e82856be403d58e050f32d (diff) | |
download | serd-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.
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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) { |