From 9eee20ada8974e53227fa77e8dc0013ceaca88a3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 22:58:12 +0100 Subject: Add nonnull and nullable attributes to API This will warn if NULL is passed to any nonnull-annotated parameter, and is also supported by sanitizers which can check for violations at runtime. Unfortunately, it is currently only supported by clang. GCC has a similar feature in the nonnull attribute, but this has a different syntax (it's a function attribute) and is more dangerous since it is used by the optimizer to assume a null pointer is undefined behavior. This one just warns and still allows code to handle the situation gracefully, which I think is more appropriate for a library API. Note that this optimization behavior is not some unlikely edge case: switching these attributes to the GCC one will break release builds. --- test/test_reader_writer.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 60f8805f..41f57e77 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -286,7 +286,15 @@ test_reader(const char* path) SerdNode g = serd_node_from_string(SERD_URI, USTR("http://example.org/")); serd_reader_set_default_graph(reader, &g); serd_reader_add_blank_prefix(reader, USTR("tmp")); + +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wnonnull" +#endif serd_reader_add_blank_prefix(reader, NULL); +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif assert(serd_reader_read_file(reader, USTR("http://notafile"))); assert(serd_reader_read_file(reader, USTR("file:///better/not/exist"))); -- cgit v1.2.1