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

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

[Octave-bug-tracker] [bug #59238] load variables from file: the next sav


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #59238] load variables from file: the next saving operation produces a faulty file
Date: Tue, 20 Oct 2020 14:29:20 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36 Edg/86.0.622.43

Follow-up Comment #14, bug #59238 (project octave):

All characters are read. But the size of the loaded string is wrong:

>> size (cell_str{1})
ans =
    1   18
>> size (cell_str2{1})
ans =
    1   15


It contains the CRLF line endings where it probably should only contain LF
line endings like the original string `cell_str2`.

I'm looking at the code in `load-save.cc`:
We are opening the ifstream when loading from a file in binary mode (line
1317). That means that *all* bytes (including the CRLF) will be read as they
are stored in the file on all platforms. The comment above suggests that this
was a conscious decision.
But it also looks like we open the ofstream for saving the data to a file in
binary mode as well (line 1479). IIUC, that means that *all* bytes should be
written as is to the output stream. Only if we'd be opening the stream in text
mode, the line ending would be converted to CRLF on Windows (see e.g. [1]).
I wonder where the CRLF come from in the first place. They should not be
there...

[1]: https://en.cppreference.com/w/cpp/io/c/FILE#Binary_and_text_modes

    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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