bugGNU Octave - Bugs: bug #49696, Matlab eval function accepts a...

 
 

bug #49696: Matlab eval function accepts a column vector string input

Submitter:  Guillaume <gyom>
Submitted:  Thu 24 Nov 2016 11:57:39 AM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 09 Jun 2019 04:20:51 AM UTC, comment #5: 

I decided that Octave should err on the side of strict input validation.  As of this changeset (https://hg.savannah.gnu.org/hgweb/octave/rev/58bdc2d98481), Octave will only accept a 1xN character vector for the input to eval().  This doesn't seem to be a hardship.  Any programmer can simply transpose a column vector in to a row vector if that is what they have.  I check with Matlab and a multi-row character array or a character array with more than 2 dimensions results in an error.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Fri 25 Nov 2016 05:03:31 PM UTC, comment #4: 

Both Octave and Matlab return false for strcmp('abc',strvcat('a','b','c')) so I would assume the issue is not that widespread.

Not sure which other functions to test for. Out of curiosity, I tried this in Matlab


>> f=figure(['color']',[1 1 1])
f =
  Figure (1) with properties:


Octave chokes on it:


octave> f=figure(['color']',[1 1 1])
error: set: ambiguous figure property name c; possible matches:
children          closerequestfcn   colormap          currentaxes       currentobject
clipping          color             createfcn         currentcharacter  currentpoint


I'm not sure this really matters though...

Guillaume <gyom>
Fri 25 Nov 2016 04:35:45 PM UTC, comment #3: 

Is it generally true that Matlab will treat an Nx1 character array the same as a 1xN character array?  Or is that just true of some functions?  It would be easy enough to fix just eval for compatibility, but I'm wondering if this is something that should be fixed globally by having string_value treat Nx1 and 1xN arrays the same.

John W. Eaton <jwe>
Group administrator
Thu 24 Nov 2016 05:14:24 PM UTC, comment #2: 

Thanks for your feedback.

For the char array input, I guess this is related to what is described in bug #49536.

For the 1xN vs Nx1 vector, I agree with you. I came across this with an evaluated string that was obtained from reading from a file with fread(fid,'char*').

Guillaume <gyom>
Thu 24 Nov 2016 02:47:32 PM UTC, comment #1: 

Confirmed.  Octave should definitely either produce an error, or at least a warning that it is using only the first line, if the input is an array.

It also doesn't seem unreasonable to me to require a 1XN vector.  That is how most strings would be presented and an Nx1 is likely to be an error.  If the user really has such a string they can always transpose it before calling eval.


Rik <rik5>
Group administrator
Thu 24 Nov 2016 11:57:39 AM UTC, original submission:  

In Octave the string input of the eval function has to be a 1xN array while Matlab allows 1xN and Nx1. Matlab throws an error if the input is MxN while Octave will execute the first row.

Matlab:


>> str = 'disp(''hello'')'

str =

disp('hello')

>> eval(str)
hello
>> eval(str')
hello
>> str = strvcat('disp(''hello'')','disp(''hi'')')

str =

disp('hello')
disp('hi')

>> eval(str)
Error: Unexpected MATLAB expression.

>> eval(str')
Error: Unexpected MATLAB expression.


Octave:


> str = 'disp(''hello'')'
str = disp('hello')
> eval(str)
hello
> eval(str')
error: 'd' undefined near line 1 column 1
> str = strvcat('disp(''hello'')','disp(''hi'')')
str =

disp('hello')
disp('hi')

> eval(str)
hello
> eval(str')
error: 'dd' undefined near line 1 column 1


Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #39071:  oct-parse.in.yy added by apx6174 (154KiB - application/octet-stream - Hi, New here. Fixed the bug. Now the user is given a warning in the event that the argument has more than 1 row. )
file #39072:  changeset.txt added by apx6174 (706B - text/plain - Hi, New here. Fixed the bug. Now the user is given a warning in the event that the argument has more than 1 row. )

 

Carbon-Copy List
  • -email is unavailable- added by apx6174 (Updated the item)
  • -email is unavailable- added by apx6174
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by gyom (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-09 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2016-11-29 rik5 SummaryDimensions of the eval function string input Matlab eval function accepts a column vector string input
    2016-11-28 rik5 Dependencies- Depends on bugs #49536
    2016-11-25 apx6174 Attached File- Added oct-parse.in.yy, #39071
        Attached File- Added changeset.txt, #39072
    2016-11-25 apx6174 Carbon-Copy- Added -email is unavailable-
    2016-11-24 rik5 Severity3 - Normal 2 - Minor
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-8ccc.
    Corresponding source code