File: avoid-underflow

package info (click to toggle)
pocketsphinx 0.8%2B5prealpha%2B1-15
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 44,124 kB
  • sloc: ansic: 22,159; sh: 11,483; python: 657; makefile: 381; perl: 301
file content (46 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
https://github.com/cmusphinx/pocketsphinx/issues/252

commit fbd61be8797fac29519e5317e79012ed2e7296e1
Author: David Huggins-Daines <dhdaines@gmail.com>
Date:   Wed Sep 28 14:19:32 2022 -0400

    fix: avoid underflow in GMM computation
    
    MIPS, among others, will *not* fail gracefully here (should fix #252, #199)

diff --git a/src/libpocketsphinx/ptm_mgau.c b/src/libpocketsphinx/ptm_mgau.c
index 85bc7aab..bca65faf 100644
--- a/src/libpocketsphinx/ptm_mgau.c
+++ b/src/libpocketsphinx/ptm_mgau.c
@@ -126,7 +126,10 @@ eval_topn(ptm_mgau_t *s, int cb, int feat, mfcc_t *z)
             obs += 4;
             mean += 4;
         }
-        insertion_sort_topn(topn, i, (int32)d);
+        if (d < (mfcc_t)INT_MIN)  /* Redundant if FIXED_POINT */
+            insertion_sort_topn(topn, i, INT_MIN);
+        else
+            insertion_sort_topn(topn, i, (int32)d);
     }
 
     return topn[0].score;
@@ -213,7 +216,10 @@ eval_cb(ptm_mgau_t *s, int cb, int feat, mfcc_t *z)
         }
         if (i < s->max_topn)
             continue;       /* already there.  Don't insert */
-        insertion_sort_cb(&cur, worst, best, cw, (int32)d);
+        if (d < (mfcc_t)INT_MIN)  /* Redundant if FIXED_POINT */
+            insertion_sort_cb(&cur, worst, best, cw, INT_MIN);
+        else
+            insertion_sort_cb(&cur, worst, best, cw, (int32)d);
     }
 
     return best->score;
@@ -271,7 +277,6 @@ ptm_mgau_codebook_norm(ptm_mgau_t *s, mfcc_t **z, int frame)
             if (norm < s->f->topn[i][j][0].score >> SENSCR_SHIFT)
                 norm = s->f->topn[i][j][0].score >> SENSCR_SHIFT;
         }
-        assert(norm != WORST_SCORE);
         for (i = 0; i < s->g->n_mgau; ++i) {
             int32 k;
             if (bitvec_is_clear(s->f->mgau_active, i))