bugGNU Octave - Bugs: bug #41648, fread not working with skip...

 
 

bug #41648: fread not working with skip parameter

Submitter:  None
Submitted:  Thu 20 Feb 2014 06:03:11 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Tiago Loureiro Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.8.0
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 22 Feb 2014 08:03:21 PM UTC, comment #7: 

Everything checks out now and fread seems to behave as it did in 3.6.4.  Closing report.

Rik <rik5>
Group administrator
Sat 22 Feb 2014 06:07:41 PM UTC, comment #6: 

I checked in the following additional change:

  http://hg.savannah.gnu.org/hgweb/octave/rev/0bdecd41b2dd

John W. Eaton <jwe>
Group administrator
Sat 22 Feb 2014 04:19:34 PM UTC, comment #5: 

The patch is almost perfect.  The only difference now is that when the read + skip reaches the EOF the 3.8.1 version adds a zero element while the 3.6.4 version correctly finds no data to read and doesn't append a zero element.

Example:


fread (fid, [3,Inf], '3*uint8',1)

On 3.6.4
ans =

    0    4    8   12
    1    5    9   13
    2    6   10   14

On 3.8.1

ans =

    0    4    8   12    0
    1    5    9   13    0
    2    6   10   14    0


Similarly


fread (fid, [1,Inf], '4*uint16',3)

On 3.6.4
ans =

    256    770   1284   1798   3083   3597

On 3.8.1
ans =

    256    770   1284   1798   3083   3597      0


Rik <rik5>
Group administrator
Fri 21 Feb 2014 11:15:09 PM UTC, comment #4: 

Rik:

I modified your patch and checked it in:

  http://hg.savannah.gnu.org/hgweb/octave/rev/fdd27f68b011

I think this fixes the new problem you reported, plus another that I found while testing (skipping past the end of the file was not skipping when it should have skipped to EOF).  If you agree that the problems are fixed, please close this report.

Thanks.

John W. Eaton <jwe>
Group administrator
Fri 21 Feb 2014 12:26:07 AM UTC, comment #3: 

I've attached a patch that fixes the skip problem for me.

I will say that this seems to have exposed another issue.  When I run the following code I get a 2-column output which is most definitely wrong.


fid = fopen ("test.bin", "rb");
fread (fid, 3, "2*uint8",10)
ans =

    0   13
    1    0
   12    0


This seems related, although my patch doesn't fix it so perhaps it should be a different bug report.



(file #30624)

Rik <rik5>
Group administrator
Fri 21 Feb 2014 12:20:02 AM UTC, comment #2: 

I probably broke it when I tried to make fread more efficient.  I'll try to take a look at this, but if someone else would like to work on it just let me know that you are.

John W. Eaton <jwe>
Group administrator
Thu 20 Feb 2014 11:52:45 PM UTC, comment #1: 

Running the first example in version 3.6.4 does yield [0, 2, 4, ...] so something was broken between then and the 3.8.0 release.  Marking the bug as confirmed.

Rik <rik5>
Group administrator
Thu 20 Feb 2014 06:03:11 PM UTC, original submission:  

The fread function is not behaving correctly when skipping after a read.

With the following data in a binary file (attached):

000102030405060708090A0B0C0D0E0F

Reading it with the following commands:


fid=fopen("test.bin","rb","ieee-be");
a=fread(fid, inf, "uint8",1);
a'


should yield (in hex):

ans =

    0    2    4    6    8    10   12   14


but returns instead (in hex):


ans =

    0    2    3    4    5    6    7    8    9   10   11   12   13   14   15


It is interesting to note that if called sequentially like this with skip=1:

fread(fid, 1, "uint8",1);


the correct sequence is read.

However, if called like this:

fread(fid, inf, "2*uint8",2)


it yields a strange sequence:

ans =

    0    1    4    5    6    7    8    9   10   11   12   13   14   15


Note the first two bytes being read correctly, and then the skip is forgotten and the rest of the file is read. The expected sequence would be instead:

ans =

    0    1    4    5    8    9   12   13


Finally, when doing the following:


fread(fid, 1, "2*uint8",2)


octave crashes with the message "Aborted".

It is as if it is getting confused between bytes to read and elements to read, and that the logic of whether to skip or not is broken.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #30624:  patch.fread_skip added by rik5 (679B - application/octet-stream)
file #30618:  test.bin added by None (16B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-02-22 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2014-02-21 rik5 Attached File- Added patch.fread_skip, #30624
        Assigned tojwe None
    2014-02-21 jwe Assigned toNone jwe
    2014-02-20 rik5 StatusNone Confirmed
    2014-02-20 None Attached File- Added test.bin, #30618

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code