octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #63931] Binary fwrite writes incorrect data to


From: Dmitri A. Sergatskov
Subject: [Octave-bug-tracker] [bug #63931] Binary fwrite writes incorrect data to file
Date: Wed, 15 Mar 2023 21:00:33 -0400 (EDT)

Follow-up Comment #4, bug #63931 (project octave):

I can reproduce this bug on comiles where I can reproduce bug 
https://savannah.gnu.org/bugs/?63415


>> clear all

fid = fopen ("m_eye.bin", "wb", "ieee-le");
matA = eye (100,150);
n = fwrite (fid, matA, "double");
fclose(fid);

assert (stat ("m_eye.bin").size == numel(matA) * 8)

fid = fopen ("m_rand.bin", "wb", "ieee-le");
matB = rand (100,150);
n = fwrite (fid, matB, "double");
fclose(fid);

assert (stat ("m_rand.bin").size == numel(matB) * 8)

fid = fopen ("m_eye.bin", "rb");
matC = fread (fid, inf, "double");
fclose(fid);

fid = fopen ("m_rand.bin", "rb");
matD = fread (fid, inf, "double");
fclose(fid);

assert (all (matC == matA(:)))
assert (all (matD == matB(:)))

clear ans fid
whos
error: assert (stat ("m_rand.bin").size == numel (matB) * 8) failed
error: called from
    assert at line 107 column 11
error: assert (all (matC == matA (:))) failed
error: called from
    assert at line 107 column 11
error: mx_el_eq: nonconformant arguments (op1 is 14406x1, op2 is 15000x1)
Variables visible from the current scope:

variables in scope: top scope

  Attr   Name        Size                     Bytes  Class
  ====   ====        ====                     =====  =====
         matA      100x150                      800  double
         matB      100x150                   120000  double
         matC    15000x1                     120000  double
         matD    14406x1                     115248  double
         n           1x1                          8  double

Total is 59407 elements using 356056 bytes

>> val = hex2dec('a7');
a = ones(2400,1)*val;
f = fopen('a.a','wb');
fwrite(f,a,'uint8');
fclose(f);

f = fopen('a.a','rb');
b = fread(f,2400,'uint8');
fclose(f);

a(1)
b(1)
ans = 167
ans = 63
>>



Dmitri.
-- 



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63931>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]