diff options
author | Damien Zammit <damien@zamaudio.com> | 2014-04-29 06:44:40 +1000 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2014-04-29 06:48:29 +1000 |
commit | 2f6065b32c26dba0f7ea5da5c980d0406c36cc55 (patch) | |
tree | 32e72f96535480bbb6ae346e69866c03a61a6b3a /libs/evoral/src/SMF.cpp | |
parent | f5276a104c2d544cf537db9e9b8de9022de7ad56 (diff) |
Fixed problem where importing invalid midi files caused crash.3.5.380
Diffstat (limited to 'libs/evoral/src/SMF.cpp')
-rw-r--r-- | libs/evoral/src/SMF.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index b84507818c..6557a01b80 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -67,6 +67,28 @@ SMF::seek_to_track(int track) } } +/** Attempt to open the SMF file just to see if it is valid. + * + * \return true on success + * false on failure + */ +bool +SMF::test(const std::string& path) +{ + PBD::StdioFileDescriptor d (path, "r"); + FILE* f = d.allocate (); + if (f == 0) { + return false; + } + + smf_t* test_smf; + if ((test_smf = smf_load (f)) == NULL) { + return false; + } + smf_delete (test_smf); + return true; +} + /** Attempt to open the SMF file for reading and/or writing. * * \return 0 on success |