bugGNU Octave - Bugs: bug #47434, fwrite of integer types on Solaris...

 
 

bug #47434: fwrite of integer types on Solaris writes little-endian (should be big-endian)

Submitter:  Mike Miller <mtmiller>
Submitted:  Thu 17 Mar 2016 01:11:15 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  mtmiller
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Solaris/SunOS
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 25 May 2016 10:13:34 PM UTC, comment #5: 

Interesting timing, but otherwise unrelated I think.

In my testing there were no bugs on typical little-endian systems, either reading or writing, big or little endian data. The only bug was on big-endian systems, where only little-endian files could be written (but either could be read correctly).

Mike Miller <mtmiller>
Group Member
Wed 25 May 2016 10:07:01 PM UTC, comment #4: 

Possibly related on the read side, see bug #48018.

I've asked for details, but this may be a case where we are not reading big endian values correctly on a little endian system.

Rik <rik5>
Group administrator
Wed 25 May 2016 07:33:45 PM UTC, comment #3: 

The patch fixes the bug on the SPARC system I have access to, no additional errors seen on that, or on my standard x86_64 build. Pushed to stable and merged to default

http://hg.savannah.gnu.org/hgweb/octave/rev/1e81dd035639

Manual fixup was needed for merging to default because of the change from oct_mach_info to octave::mach_info.

Mike Miller <mtmiller>
Group Member
Wed 25 May 2016 02:45:18 AM UTC, comment #2: 

I think I have found the logic error here, attaching a diff I am currently testing. It takes a long time to rebuild on the Solaris test setup I have access to, but once I confirm that fwrite works as expected I'll push this to the stable branch.



(file #37253)

Mike Miller <mtmiller>
Group Member
Thu 17 Mar 2016 01:12:33 AM UTC, comment #1: 

And I didn't say explicitly, but this only applies to integer types. Floating point formats do write in the correct order, either native, big-endian, or little-endian as specified.

Mike Miller <mtmiller>
Group Member
Thu 17 Mar 2016 01:11:15 AM UTC, original submission:  

Writing multi-byte integers using fwrite writes them in little-endian format regardless of what ARCH parameter is given to fopen or fwrite. The default should be big-endian, and that is what Octave thinks it is internally, but the bytes are written in little-endian order.

Example:


>> nm = tempname; fid = fopen (nm, "wb"); fwrite (fid, 1, "int16"); fclose (fid); system (sprintf ("od -tx1 %s", nm)); unlink (nm);
0000000 01 00
0000002
>> nm = tempname; fid = fopen (nm, "wb"); fwrite (fid, 1, "int32"); fclose (fid); system (sprintf ("od -tx1 %s", nm)); unlink (nm);
0000000 01 00 00 00
0000004
>> nm = tempname; fid = fopen (nm, "wb"); fwrite (fid, 1, "int64"); fclose (fid); system (sprintf ("od -tx1 %s", nm)); unlink (nm);
0000000 01 00 00 00 00 00 00 00
0000010


The results are the same if either fopen or fwrite are given any of the possible ARCH values.

I've started looking into this but getting lost in the octave_stream::write templates and data conversion options.

Mike Miller <mtmiller>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #37253:  big-endian.diff added by mtmiller (1KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-05-25 mtmiller StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2016-05-25 mtmiller Attached File- Added big-endian.diff, #37253
        Assigned toNone mtmiller

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code