Mindwerks / wildmidi

WildMIDI is a simple software midi player which has a core softsynth library that can be used with other applications.
https://github.com/Mindwerks/wildmidi
Other
201 stars 41 forks source link

Save midi reads wrong argv if there are no path seperators in the file path #227

Closed oreo639 closed 3 years ago

oreo639 commented 3 years ago

When trying to save as midi through wildmidi, it tries to read the wrong argv to get the output filename if there are no path separators. This results in NULL getting passed to mk_midifile_name() if you do not specify the output file name after the input filename.

This is due to here: https://github.com/Mindwerks/wildmidi/blob/master/src/wildmidi.c#L1999-L2000

If there is a path separator it uses argv[optind-1], but if there isn't, it uses argv[optind].

You can reproduce this simply by playing any xmi, mus, etc file without path separators in the input, then press m during playback.

sezero commented 3 years ago

Nice catch - I'm surprised no one else had caught it before. Does the following work OK for you?

diff --git a/src/wildmidi.c b/src/wildmidi.c
index a9ae0f1..fd9c5e7 100644
--- a/src/wildmidi.c
+++ b/src/wildmidi.c
@@ -1997,7 +1997,7 @@ int main(int argc, char **argv) {
                         WildMidi_ClearError();
                     } else {
                         char *real_file = FIND_LAST_DIRSEP(argv[optind-1]);
-                        if (!real_file) real_file = argv[optind];
+                        if (!real_file) real_file = argv[optind-1];
                         else real_file++;
                         mk_midifile_name(real_file);
                         printf("\rWriting %s: %u bytes.\r\n", midi_file, getmidisize);
oreo639 commented 3 years ago

Yep.

sezero commented 3 years ago

Fixed by commit 1a61d977650ef7a91990dafb29c321e732bfc3a9

Not making a new release just for this one yet, though.