summaryrefslogtreecommitdiffstats
path: root/src
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 /src
parenta38dae594fedffd29c90839bf12b9a874367cf41 (diff)
downloadlilv-57137bcbee853e8924631f20cb4e3e9a64fd84ba.tar.gz
lilv-57137bcbee853e8924631f20cb4e3e9a64fd84ba.tar.bz2
lilv-57137bcbee853e8924631f20cb4e3e9a64fd84ba.zip
Fix unlikely undefined behavior when saving state
Diffstat (limited to 'src')
-rw-r--r--src/state.c19
1 files changed, 17 insertions, 2 deletions
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;