changeset 305:8cec6eb40526

Guard against too-short tracks. Fixes a segfault on attempting to index the AWAL.frames1.mfcc20.adb with default parameters.
author mas01cr
date Tue, 05 Aug 2008 15:34:10 +0000
parents 2d6efbe56bb8
children 921ba500a024
files index.cpp
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/index.cpp	Tue Aug 05 13:38:36 2008 +0000
+++ b/index.cpp	Tue Aug 05 15:34:10 2008 +0000
@@ -226,7 +226,20 @@
 
 int audioDB::index_insert_track(Uns32T trackID, double** fvpp, double** snpp, double** sppp){
   // Loop over the current input track's vectors
-  Uns32T numVecs = (trackTable[trackID]>O2_MAXTRACKLEN?O2_MAXTRACKLEN:trackTable[trackID]) - sequenceLength + 1 ;
+  Uns32T numVecs = 0;
+  if (trackTable[trackID] > O2_MAXTRACKLEN) {
+    if (O2_MAXTRACKLEN < sequenceLength - 1) {
+      numVecs = 0;
+    } else {
+      numVecs = O2_MAXTRACKLEN - sequenceLength + 1;
+    }
+  } else {
+    if (trackTable[trackID] < sequenceLength - 1) {
+      numVecs = 0;
+    } else {
+      numVecs = trackTable[trackID] - sequenceLength + 1;
+    }
+  }
   vv = index_initialize_shingles(numVecs);
 
   for( Uns32T pointID = 0 ; pointID < numVecs; pointID++ )