shithub: sf2mid

Download patch

ref: dea79b7c4e5daa857fd33b383ea3de34c77a670c
parent: 1d506023c7b62d91572df862f7b116dc15661842
author: Ellie <64124388+ell1e@users.noreply.github.com>
date: Wed Sep 13 14:52:05 EDT 2023

Fix conditions evaluating based on uninitialized memory (#63)

(benign, but might mask legitimate errors in valgrind, libasan/sanitizer, etc.)

--- a/tsf.h
+++ b/tsf.h
@@ -1762,7 +1762,7 @@
 	struct tsf_voice *v, *vEnd;
 	float pitchShift = (c->pitchWheel == 8192 ? c->tuning : ((c->pitchWheel / 16383.0f * c->pitchRange * 2.0f) - c->pitchRange + c->tuning));
 	for (v = f->voices, vEnd = v + f->voiceNum; v != vEnd; v++)
-		if (v->playingChannel == channel && v->playingPreset != -1)
+		if (v->playingPreset != -1 && v->playingChannel == channel)
 			tsf_voice_calcpitchratio(v, pitchShift, f->outSampleRate);
 }
 
@@ -1841,7 +1841,7 @@
 	if (!c) return 0;
 	if (gainDB == c->gainDB) return 1;
 	for (v = f->voices, vEnd = v + f->voiceNum, gainDBChange = gainDB - c->gainDB; v != vEnd; v++)
-		if (v->playingChannel == channel && v->playingPreset != -1)
+		if (v->playingPreset != -1 && v->playingChannel == channel)
 			v->noteGainDB += gainDBChange;
 	c->gainDB = gainDB;
 	return 1;