bugGNU Octave - Bugs: bug #35999, strread error on empty string and...

 
 

bug #35999: strread error on empty string and related textread warning on empty file

Submitted by:  None
Submitted on:  Sun 25 Mar 2012 05:21:53 PM UTC  
 
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: Originator Email: -unavailable-
Open/Closed: ClosedRelease: 3.6.1
Operating System: Microsoft Windows

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sun 25 Mar 2012 11:13:24 PM UTC, comment #3:

Thanks Philip.

I applied your patch and added a %!test for the new behavior (http://hg.savannah.gnu.org/hgweb/octave/rev/9fc75cdf61ab).

Closing this report.

Rik <rik5>
Project Administrator
Sun 25 Mar 2012 09:28:47 PM UTC, comment #2:

(?guru? now if only that were true. But thx I'm flattered :-) )

Indeed, easy fix. Changeset attached

Why anyone would want to read from an empty string is beyond me, but I can imagine scripts feeding empty strings to strread in some corner cases. IMO in that situation the most sensible action would be to silently return empty output args, so that the calling scripts wouldn't be interrupted.
If users prefer errors in such cases, they'd better include checks for empty strings in the calling scripts before the call to strread.

I've not checked output arg type, you just get the requested number of empty args as [].

BTW textread has just been finally fixed today for some other reason, along the way I've also fixed this very bug. See https://savannah.gnu.org/patch/?7748 (I'm awaiting verification before I push that)
BTW even if that textread fix hadn't been made, strread would now catch it anyway.

Can one of the devs please verify my attached patch, please?

(file #25467)

Philip Nienhuis <philipnienhuis>
Project Member
Sun 25 Mar 2012 08:25:12 PM UTC, comment #1:

Confirmed on a recent tip. This is probably trivial to fix by checking 'isempty()' on the input string. I've added the guru for strread to the CC list so that he can take a look at this.

Rik <rik5>
Project Administrator
Sun 25 Mar 2012 05:21:53 PM UTC, original submission:

Here is the strread call causes error:
---------------------------------------------
octave:1> [a,b]=strread('', '%s %d')
error: strread: subscript indices must be either positive integers or logicals
error: called from:
error: C:\Octave\Octave3.6.1_gcc4.6.2\share\octave\3.6.1\m\io\strread.m at line 362, column 1
---------------------------------------------

However, if I put any space into the input string, strread works as desired:
----------------------
octave:2> [a,b]=strread(' ', '%s %d')
a = {}(0x1)
b = [](0x1)
----------------------

In parallel, textread would not set the output argument when a file is empty, and issue a warning and an error. But textread works as desired if there is any space in the input file.
-----------------------------------------------
% fubar is an empty file
octave:30> [a,b]=textread('fubar', '%s %d')
warning: textread: empty file
error: element number 1 undefined in return list
% after adding one space into fubar
octave:4> [a,b]=textread('fubar', '%s %d')
a =
{
[1,1] =
}
b = 0

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #25467:  strread_emptystr.patch added by philipnienhuis (842B - application/x-download)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by philipnienhuis (Updated the item)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by rik5
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 27 Mar 2012 04:05:22 AM UTCrik5Open/ClosedOpen=>Closed
    Sun 25 Mar 2012 11:13:24 PM UTCrik5StatusConfirmed=>Fixed
    Sun 25 Mar 2012 09:28:47 PM UTCphilipnienhuisAttached File-=>Added strread_emptystr.patch, #25467
    Sun 25 Mar 2012 08:25:12 PM UTCrik5CategoryNone=>Libraries
      Item GroupOther=>Incorrect Result
      StatusNone=>Confirmed
      Carbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1