src/io/source_sndfile.c: avoid seeking in closed file
authorPaul Brossier <piem@piem.org>
Sun, 26 Feb 2017 22:33:09 +0000 (23:33 +0100)
committerPaul Brossier <piem@piem.org>
Sun, 26 Feb 2017 22:33:09 +0000 (23:33 +0100)
src/io/source_sndfile.c

index 2f09d13..5d009c5 100644 (file)
@@ -295,6 +295,11 @@ uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) {
 uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) {
   uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio);
   sf_count_t sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET);
+  if (s->handle == NULL) {
+    AUBIO_ERR("source_sndfile: failed seeking in %s (file not opened?)\n",
+        s->path);
+    return AUBIO_FAIL;
+  }
   if (sf_ret == -1) {
     AUBIO_ERR("source_sndfile: Failed seeking %s at %d: %s\n", s->path, pos, sf_strerror (NULL));
     return AUBIO_FAIL;