#923 First linein on read-only file returns empty line


As subject. Running the attached testcase displays:

First line of $data-n.txt is: Line 1 of file $data-n.txt
Second line of $data-n.txt is: Line 2 of file $data-n.txt
First line of $data-r.txt is:
Second line of $data-r.txt is: Line 1 of file $data-r.txt

where the two files are identical except the second has the read-only attribute set. This on Windows (both XP and 7).


  • Mike Cowlishaw

    Mike Cowlishaw - 2010-08-07

    Illustrate read-only read problem

  • Mark Miesfeld

    Mark Miesfeld - 2010-08-08

    Hi Mike,

    Thanks for the test program. I see the same thing in trunk on XP.

    I'll try and take a look into it some time today. Athough i might not have time.

  • Mike Cowlishaw

    Mike Cowlishaw - 2010-08-08

    Thanks. No big hurry .. I have coded a workaround. But it is a nasty gotcha .. cost me many hours before I spotted the subtle difference between my two 'identical' machines -- on one the key file (literally .. a one-liner that held an encryption key) was R/O, on the other it was not ...

  • jfaucher

    jfaucher - 2010-08-09

    (Mark, I don't plan to commit, unless you want).
    The implicit open tries to open RW, and since it fails, tries to open RO. But the error code in fileInfo.errInfo is not cleared. The attached patch fixes that.
    I added also a reset of the error code in StreamInfo.resetFields, no relation with the current defect, but seems safer to do that...

    In SysFile.cpp, errInfo is never reset, except in SysFile::SysFile and SysFile::close. It's probably a design decision, because currently, only StreamInfo::notreadyError clears errInfo.
    But I wonder if we can't have a similar problem elsewhere... A radical fix would be to clear the error on entry in each method of SysFile which can set it, but I have the feeling that it was not done for good reasons...

  • jfaucher

    jfaucher - 2010-08-09
  • Mark Miesfeld

    Mark Miesfeld - 2010-08-09

    Commited revision 6090.


    That's funny, I commited my fix probably about the same time you wrote this.

    I used clearErrors() to reset errInfo after the initial try to open in read / write mode in implicitOpen fails. I don't think we would have a problem in other areas because in implicitOpen is the only place that we retry to open a file after an explicit failure. (I'll have to recheck that, but I thinkt that's true.)

  • Mark Miesfeld

    Mark Miesfeld - 2010-09-08

    Put in group v4.0.2 to signal this bug fix should be in the next bug fix release. This will actually be the 4.1.0 release.

  • Mark Miesfeld

    Mark Miesfeld - 2010-09-11

    Committed revision 6180.

    4.1.0 merge.

  • Mark Miesfeld

    Mark Miesfeld - 2010-12-05

    The fix for this item was in the 4.1.0 release.



Cancel  Add attachments

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks