[Kst] [Bug 120823] Crash if attempt to read past end of dirfile.

netterfield at astro.utoronto.ca netterfield at astro.utoronto.ca
Fri Jan 27 17:55:56 CET 2006


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=120823         




------- Additional Comments From netterfield astro utoronto ca  2006-01-27 17:55 -------
OK.  I think Andrew is right.  As the code was designed, the first assert is invalid: 
assert(new_nf - NF - 1 > 0 || new_nf - NF - 1 == -1);  should be       assert(new_nf - NF - 1 >=0 || new_nf - NF - 1 == -1);

or not be there at all.

What the code was suppose to do, on a start past eof, is to read only the first sample in the file.

Of course George is also right - this is not the most clever of all possible solutions.  In an attempt to be more clever, the patch below detects the start past eof condition, and makes a 1 sample long vector which contains only NaN.  I have not fully tested what happens in all cases when you try to make curves, equations, psds, etc, of vectors with only 1 sample, which is a NaN, but at first try, it seems ok (but so does deleting the assert).

Index: kstrvector.cpp
===================================================================
--- kstrvector.cpp      (revision 502941)
+++ kstrvector.cpp      (working copy)
 @ -430,7 +430,8  @
   int i, k, shift, n_read=0;
   int ave_nread;
   int new_f0, new_nf;
-
+  bool start_past_eof = false;
+
   checkIntegrity();

   if (DoSkip && Skip < 2 && SPF == 1) {
 @ -462,6 +463,7  @
       // Tried to read starting past the end.
       new_f0 = 0;
       new_nf = 1;
+      start_past_eof = true;
     }
   }

 @ -575,7 +577,10  @
     }

     // read the new data from file
-    if (_file->samplesPerFrame(_field) > 1) {
+    if (start_past_eof) {
+      _v[0] = NAN;
+      n_read = 1;
+    } else if (_file->samplesPerFrame(_field) > 1) {
       assert(new_nf - NF - 1 > 0 || new_nf - NF - 1 == -1);
       assert(new_f0 + NF >= 0);
       assert(new_f0 + new_nf - 1 >= 0);


More information about the Kst mailing list