summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-02-02 20:14:05 +0000
committerDavid Robillard <d@drobilla.net>2013-02-02 20:14:05 +0000
commitbf23b9f975ec97d20ba6381f2457e7b7d6ec0369 (patch)
tree52df2281c1dba7fed598e55d5dabe9e219f84a65
parentdd51340700469210bbbff0424f6ebe85d32e9524 (diff)
downloadlilv-bf23b9f975ec97d20ba6381f2457e7b7d6ec0369.tar.gz
lilv-bf23b9f975ec97d20ba6381f2457e7b7d6ec0369.tar.bz2
lilv-bf23b9f975ec97d20ba6381f2457e7b7d6ec0369.zip
Require a URI for lilv_state_to_string() and fail gracefully otherwise.
Fail gracefully when lilv_state_new_from_string() is called on NULL. Fixes #865. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5030 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--NEWS4
-rw-r--r--lilv/lilv.h5
-rw-r--r--src/state.c9
-rw-r--r--test/lilv_test.c9
4 files changed, 26 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index bfaeea2..2da319e 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ lilv (0.15.0) unstable;
* Add lilv_world_ask() for simply checking if a statement exists
* Add lilv_nodes_merge()
* Make lilv_plugin_get_port_by_designation() return a const pointer
+ * Require a URI for lilv_state_to_string() and fail gracefully otherwise
+ * Fail gracefully when lilv_state_new_from_string() is called on NULL
* Make state loading functions fall back to lv2:default for port values,
so a plugin description can be loaded as default state
* Ignore state ports with no value instead of printing an error
@@ -15,7 +17,7 @@ lilv (0.15.0) unstable;
* lilvmm.hpp: Add several missing methods
* Update to waf 1.7.8 and autowaf r90 (install docs to versioned directory)
- -- David Robillard <d@drobilla.net> Sat, 26 Jan 2013 21:14:13 -0500
+ -- David Robillard <d@drobilla.net> Sat, 02 Feb 2013 15:10:18 -0500
lilv (0.14.4) stable;
diff --git a/lilv/lilv.h b/lilv/lilv.h
index 9ee45b8..6719e67 100644
--- a/lilv/lilv.h
+++ b/lilv/lilv.h
@@ -1420,6 +1420,11 @@ lilv_state_save(LilvWorld* world,
/**
Save state to a string. This function does not use the filesystem.
+
+ @param uri URI for the state description (mandatory).
+ @param base_uri Base URI for serialisation. Unless you know what you are
+ doing, pass NULL for this, otherwise the state may not be restorable via
+ lilv_state_new_from_string().
*/
LILV_API
char*
diff --git a/src/state.c b/src/state.c
index d693f1a..3176fd1 100644
--- a/src/state.c
+++ b/src/state.c
@@ -647,6 +647,10 @@ lilv_state_new_from_string(LilvWorld* world,
LV2_URID_Map* map,
const char* str)
{
+ if (!str) {
+ return NULL;
+ }
+
SerdNode base = SERD_NODE_NULL;
SerdEnv* env = serd_env_new(&base);
SordModel* model = sord_new(world->world, SORD_SPO|SORD_OPS, false);
@@ -989,6 +993,11 @@ lilv_state_to_string(LilvWorld* world,
const char* uri,
const char* base_uri)
{
+ if (!uri) {
+ LILV_ERROR("Attempt to serialise state with no URI\n");
+ return NULL;
+ }
+
SerdChunk chunk = { NULL, 0 };
SerdEnv* env = NULL;
SerdNode base = serd_node_from_string(SERD_URI, USTR(base_uri));
diff --git a/test/lilv_test.c b/test/lilv_test.c
index f6976f6..0033885 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -1227,6 +1227,15 @@ test_state(void)
// Ensure they are equal
TEST_ASSERT(lilv_state_equals(state, state2));
+ // Check that we can't save a state with no URI
+ char* bad_state_str = lilv_state_to_string(
+ world, &map, &unmap, state, NULL, NULL);
+ TEST_ASSERT(!bad_state_str);
+
+ // Check that we can't restore the NULL string (and it doesn't crash)
+ LilvState* bad_state = lilv_state_new_from_string(world, &map, NULL);
+ TEST_ASSERT(!bad_state);
+
// Save state to a string
char* state1_str = lilv_state_to_string(
world, &map, &unmap, state, "http://example.org/state1", NULL);