[CM] Snd: save-mix segfault
Tito Latini
tito.01beta at gmail.com
Thu Apr 2 15:13:25 PDT 2015
Hi, if a mix doesn't exist, Snd crashes after save-mix.
Example I
(define mix7 (integer->mix 7))
=> #<mix 7>
(mix? mix7)
=> #f
(save-mix mix7 "bye.snd")
-- segfault
Example II
- open-sound
- add a mix
- (define mix0 (caaar (mixes)))
- save-sound
- (save-mix mix0 "crash.snd")
The null pointer (returned by md_from_id) is in save_mix (snd-mix.c:3681),
called only by copy_mix and g_save_mix. copy_mix is safe because
md = md_from_id(id);
if (!md) return(-1);
save_mix returns a io_error_t and there is not a value suitable
for a mix, so the attached patch fixes the bug in g_save_mix.
-------------- next part --------------
diff -ur snd-15~/snd-mix.c snd-15/snd-mix.c
--- snd-15~/snd-mix.c 2015-04-02 23:49:25.463887691 +0200
+++ snd-15/snd-mix.c 2015-04-02 23:49:37.209740026 +0200
@@ -3788,12 +3788,15 @@
static Xen g_save_mix(Xen m, Xen file)
{
#define H_save_mix "(" S_save_mix " mix filename) saves mix's samples in the file 'filename'"
-
+ int id;
Xen_check_type(xen_is_mix(m), m, 1, S_save_mix, "a mix");
- Xen_check_type(Xen_is_string(file), file, 2, S_save_mix, "a filename");
-
- save_mix(Xen_mix_to_C_int(m), Xen_string_to_C_string(file), MUS_NEXT, MUS_OUT_SAMPLE_TYPE);
- return(m);
+ id = Xen_mix_to_C_int(m);
+ if (mix_is_active(id)) {
+ Xen_check_type(Xen_is_string(file), file, 2, S_save_mix, "a filename");
+ save_mix(id, Xen_string_to_C_string(file), MUS_NEXT, MUS_OUT_SAMPLE_TYPE);
+ return(m);
+ }
+ return(snd_no_such_mix_error(S_save_mix, m));
}
More information about the Cmdist
mailing list