diff options
-rw-r--r-- | src/state.c | 16 | ||||
-rw-r--r-- | test/test_plugin.lv2/test_plugin.c | 24 | ||||
-rw-r--r-- | test/test_util.c | 2 |
3 files changed, 26 insertions, 16 deletions
diff --git a/src/state.c b/src/state.c index 169ccbe..48d7230 100644 --- a/src/state.c +++ b/src/state.c @@ -669,12 +669,13 @@ new_state_from_model(LilvWorld* world, chunk.len = 0; sratom_read(sratom, &forge, world->world, model, value); const LV2_Atom* atom = (const LV2_Atom*)chunk.buf; - - append_port_value(state, - (const char*)sord_node_get_string(symbol), - LV2_ATOM_BODY_CONST(atom), - atom->size, - atom->type); + if (atom) { + append_port_value(state, + (const char*)sord_node_get_string(symbol), + LV2_ATOM_BODY_CONST(atom), + atom->size, + atom->type); + } if (label) { lilv_state_set_label(state, (const char*)sord_node_get_string(label)); @@ -704,6 +705,9 @@ new_state_from_model(LilvWorld* world, const LV2_Atom* atom = (const LV2_Atom*)chunk.buf; uint32_t flags = LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE; Property prop = {NULL, 0, 0, 0, flags}; + if (!atom) { + continue; + } prop.key = map->map(map->handle, key); prop.type = atom->type; diff --git a/test/test_plugin.lv2/test_plugin.c b/test/test_plugin.lv2/test_plugin.c index 572443b..c8851d4 100644 --- a/test/test_plugin.lv2/test_plugin.c +++ b/test/test_plugin.lv2/test_plugin.c @@ -301,8 +301,10 @@ save(LV2_Handle instance, if (make_path) { char* spath = make_path->path(make_path->handle, "save"); FILE* sfile = fopen(spath, "w"); - fprintf(sfile, "save"); - fclose(sfile); + if (sfile) { + fprintf(sfile, "save"); + fclose(sfile); + } apath = map_path->abstract_path(map_path->handle, spath); store(callback_data, @@ -367,14 +369,16 @@ restore(LV2_Handle instance, } if (apath) { - char* path = map_path->absolute_path(map_path->handle, apath); - FILE* f = fopen(path, "r"); - char str[8]; - size_t n_read = fread(str, 1, sizeof(str), f); - fclose(f); - if (!!strncmp(str, "Hello\n", n_read)) { - fprintf( - stderr, "error: Restored bad file contents `%s' != `Hello'\n", str); + char* path = map_path->absolute_path(map_path->handle, apath); + FILE* f = fopen(path, "r"); + if (f) { + char str[8] = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}; + size_t n_read = fread(str, 1, 6, f); + fclose(f); + + if (!!strncmp(str, "Hello\n", n_read)) { + fprintf(stderr, "error: Restored bad file `%s' != `Hello'\n", str); + } } free_path->free_path(free_path->handle, path); } diff --git a/test/test_util.c b/test/test_util.c index 22edbbe..3063aa7 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -22,6 +22,8 @@ main(void) FILE* const fa = fopen(a_path, "w"); FILE* const fb = fopen(b_path, "w"); + assert(fa); + assert(fb); fprintf(fa, "AA\n"); fprintf(fb, "AB\n"); fclose(fb); |