[Kst] branches/kst/hfi_calib/kst/kst/datasources/planck

George Staikos staikos at kde.org
Wed Apr 5 17:05:35 CEST 2006


SVN commit 526764 by staikos:

fix off-by-one in skip


 M  +10 -9     planck.cpp  


--- branches/kst/hfi_calib/kst/kst/datasources/planck/planck.cpp #526763:526764
@@ -160,17 +160,18 @@
     return 0;
   }
 
-  if (skip > n || skip > count || skip > end) { // what are they thinking?
-    return 0;
-  }
-
   if (n < 0) { // reading less than 0 -> read only one sample!
     n = 1;
   }
 
-  if (s + (n-1)*skip > count) { // trying to read past the end
+  if (s + (n-1)*skip >= count) { // trying to read past the end
     kdDebug() << "TRYING TO READ PAST END.  n=" << n << endl;
-    n = (count - s) / skip + 1;
+    // n = ceil((count-s)/skip)
+    if ((count - s) % skip == 0) {
+      n = (count - s) / skip;
+    } else {
+      n = (count - s) / skip + 1;
+    }
     kdDebug() << "N IS NOW=" << n << endl;
   }
 
@@ -181,9 +182,9 @@
 
   // PIOLib doesn't have a mechanism to read with skip.  This needs to be added
   // later.  For now, we read into a temp buffer, then extract what we need.
-  double *tmp = new double[(n + 1) * skip];
-  int rc = _planckObject->readObject(field, tmp, start + s, start + s + (n + 1)*skip - 1);
-  //kdDebug() << "readObject rc=" << rc << " from=" << start+s << " to=" << start + s + (n+1)*skip -1 << endl;
+  double *tmp = new double[(n - 1) * skip + 1];
+  int rc = _planckObject->readObject(field, tmp, start + s, start + s + (n - 1) * skip);
+  //kdDebug() << "readObject rc=" << rc << " from=" << start+s << " to=" << start + s + (n - 1) * skip << endl;
   int i = 0;
   while (i < n && i*skip < rc) {
     v[i] = tmp[i * skip];


More information about the Kst mailing list