summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-11 17:12:46 +0100
committerDavid Robillard <d@drobilla.net>2020-11-11 21:47:07 +0100
commit57137bcbee853e8924631f20cb4e3e9a64fd84ba (patch)
treeb778599fabd261d1a0333fe782188a444d662b92
parenta38dae594fedffd29c90839bf12b9a874367cf41 (diff)
downloadlilv-57137bcbee853e8924631f20cb4e3e9a64fd84ba.tar.gz
lilv-57137bcbee853e8924631f20cb4e3e9a64fd84ba.tar.bz2
lilv-57137bcbee853e8924631f20cb4e3e9a64fd84ba.zip
Fix unlikely undefined behavior when saving state
-rw-r--r--NEWS3
-rw-r--r--src/state.c19
2 files changed, 19 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index d93f736..4cdd86c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,9 @@
lilv (0.24.11) unstable;
* Fix potential memory error when joining filesystem paths
+ * Fix unlikely undefined behavior when saving state
- -- David Robillard <d@drobilla.net> Wed, 11 Nov 2020 00:02:31 +0000
+ -- David Robillard <d@drobilla.net> Wed, 11 Nov 2020 16:12:07 +0000
lilv (0.24.10) stable;
diff --git a/src/state.c b/src/state.c
index 474ddbe..3591f25 100644
--- a/src/state.c
+++ b/src/state.c
@@ -95,7 +95,16 @@ rel_cmp(const void* a, const void* b, void* user_data)
static int
property_cmp(const void* a, const void* b)
{
- return ((const Property*)a)->key - ((const Property*)b)->key;
+ const Property* const a_key = ((const Property*)a)->key;
+ const Property* const b_key = ((const Property*)b)->key;
+
+ if (a_key < b_key) {
+ return -1;
+ } else if (b_key < a_key) {
+ return 1;
+ }
+
+ return 0;
}
static int
@@ -175,6 +184,10 @@ append_property(LilvState* state,
static const Property*
find_property(const LilvState* const state, const uint32_t key)
{
+ if (!state->props.props) {
+ return NULL;
+ }
+
const Property search_key = {NULL, 0, key, 0, 0};
return (const Property*)bsearch(&search_key,
@@ -466,7 +479,9 @@ lilv_state_new_from_instance(const LilvPlugin* plugin,
}
}
- qsort(state->values, state->n_values, sizeof(PortValue), value_cmp);
+ if (state->values) {
+ qsort(state->values, state->n_values, sizeof(PortValue), value_cmp);
+ }
free(sfeatures);
return state;