[Kst] branches/work/kst/1.1/kst/kst/datasources/planck

George Staikos staikos at kde.org
Fri Sep 23 17:26:58 CEST 2005


SVN commit 463326 by staikos:

add some sanity checks and possibly fix skip.  I can't really tell yet, though,
because it crashes in kdebug.


 M  +12 -8     planck.cpp  


--- branches/work/kst/1.1/kst/kst/datasources/planck/planck.cpp #463325:463326
@@ -160,12 +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*skip > count) { // trying to read past the end
-    n = (count - s) / skip;
+  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;
+    kdDebug() << "N IS NOW=" << n << endl;
   }
 
   if (s + start > end) {
@@ -175,13 +181,11 @@
 
   // 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 * skip];
-  int rc = _planckObject->readObject(field, tmp, start + s, start + s + n*skip - 1);
+  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;
   int i = 0;
-  int rctmp = rc;
-  while (rctmp >= skip) {
-    rctmp -= skip;
-    assert(i < n);
+  while (i < n && i*skip < rc) {
     v[i] = tmp[i * skip];
     ++i;
   }


More information about the Kst mailing list