# HG changeset patch # User Chris Cannam # Date 1226407884 0 # Node ID 6c28f22ea3538645d53f61b5ceb21a4bf1e44874 # Parent 330c2e11f8a992d7c1c7f37d500e19ec2b412c6f * Fix read from uninitialised memory in hmm code diff -r 330c2e11f8a9 -r 6c28f22ea353 hmm/hmm.c --- a/hmm/hmm.c Mon Nov 10 14:01:55 2008 +0000 +++ b/hmm/hmm.c Tue Nov 11 12:51:24 2008 +0000 @@ -577,6 +577,7 @@ { int i, j, t; double max; + int havemax; int N = model->N; int L = model->L; @@ -622,15 +623,18 @@ { for (j = 0; j < N; j++) { - max = -1000000; // TODO: what should this be?? = smallest possible sumlogprob + max = -1000000; + havemax = 0; + psi[t][j] = 0; for (i = 0; i < N; i++) { - if (phi[t-1][i] + log(a[i][j]) > max) + if (phi[t-1][i] + log(a[i][j]) > max || !havemax) { max = phi[t-1][i] + log(a[i][j]); phi[t][j] = max + logb[t][j]; psi[t][j] = i; + havemax = 1; } } }