# HG changeset patch # User cannam # Date 1226407884 0 # Node ID 03abd5957853c5e47807aa18d04ba568fc1c2f0d # Parent 38bf099279426094e633e28dd4ccb7bedb5eecb6 * Fix read from uninitialised memory in hmm code diff -r 38bf09927942 -r 03abd5957853 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; } } }