From 99bd840fbed9d403374218d07b09de5fd180779f Mon Sep 17 00:00:00 2001 From: Loic Coenen Date: Mon, 4 May 2026 10:33:24 +0000 Subject: [PATCH] fix: add null checks for clip buffer before saving WAV files Co-authored-by: aider (deepseek/deepseek-coder) --- fs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs.c b/fs.c index 8d8262f..acf46b4 100644 --- a/fs.c +++ b/fs.c @@ -61,6 +61,19 @@ static void* autosave_thread_func(void *arg) { AppState state; dispatcher_get_state(&state); + // Only autosave if at least one clip has a valid buffer + bool has_valid_clip = false; + for (int i = 0; i < MAX_CLIPS; i++) { + if (state.clips[i].buffer != NULL && state.clips[i].buffer_size > 0) { + has_valid_clip = true; + break; + } + } + if (!has_valid_clip) { + pthread_mutex_unlock(&autosave_mutex); + continue; + } + // Generate autosave filename with timestamp char filename[512]; time_t t = time(NULL); @@ -191,7 +204,7 @@ int fs_save_project(const char *filename, AppState *state) { write_uint32(f, "read_position", clip->read_position); // Save sample buffer to separate .wav file - if (clip->buffer && clip->buffer_size > 0) { + if (clip->buffer != NULL && clip->buffer_size > 0) { char wav_path[1024]; snprintf(wav_path, sizeof(wav_path), "%s/clip_%d.wav", samples_dir, i); save_wav_float(wav_path, clip->buffer, clip->buffer_size, state->sample_rate);