bugGNU Octave - Bugs: bug #34967, Bad behavior of structures with an...

 
 

bug #34967: Bad behavior of structures with an empty cell

Submitted by:  Henrik Alsing Friberg <hfriberg>
Submitted on:  Fri 02 Dec 2011 10:30:48 AM UTC  
 
Category: InterpreterSeverity: 2 - Minor
Priority: 3 - LowItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission Jump to the original submission)

Sat 19 Nov 2016 07:41:41 PM UTC, comment #6:

This behavior is still present in Octave 4.2.0.

Hartmut <hardy>
Sat 16 May 2015 07:02:21 PM UTC, comment #5:

I think we would want to aim for Matlab compatibility here, so I had someone test for me.

This is a zero-length struct array with one field "name".

Non-existent fields always return an error, whether the size of the struct array is zero or not, so for us this should look like:

Valid field names should return an empty cs-list when the struct array size is zero, so using it alone fails with an error but concatenation in an array should work.

Mike Miller <mtmiller>
Project Administrator
Mon 27 Jan 2014 02:27:10 AM UTC, comment #4:

The following commands still produce odd results in the current development version of Octave (4.1.0+):

I'm assuming what we want is the same behavior as if val were a non-empty struct array:

Or should array concatenation produce an error as in the assignment case, as below?

Mike Miller <mtmiller>
Project Administrator
Thu 13 Dec 2012 03:32:22 PM UTC, comment #3:

The struct command is for creating struct arrays, not scalar structs. When the value arguments of struct() are cell arrays, they get unpacked into cs-lists defining each value in the struct array. The equivalent of

is therefore

Jordi GutiƩrrez Hermoso <jordigh>
Project Administrator
Fri 02 Dec 2011 11:44:49 AM UTC, comment #2:

Hi John,

My expectation is that the following two constructions behaves the same:

and

However, the latter construction does not have the problems I have pointed out.
For example:

  • length(val) is 1.
  • ans = val.name is defined.

Thanks for the quick response..

Henrik Alsing Friberg <hfriberg>
Fri 02 Dec 2011 11:27:02 AM UTC, comment #1:

The expression

creates a 0x0 structure array with a field called "name". It doesn't have any elements, so it's size is 0x0. So your first example is the result I would expect.

Your second example shows a bug. The behavior is different in the current development sources, but there is still a bug there.

The problem in your third example is also still present in the current development sources. The 5th and 6th command lines should give errors about nonexistent structure fields. The 7th command line is correct behavior however, because val.name produces a comma-separated list, but it is empty because the structure array is empty, so there is nothing to assign.

I don't think your fourth example shows a bug in Octave because the cell array of values that arg0.contents(p1) returns is empty. Then you are trying to extract the first value which does not exist, so you are indexing outside the bounds of the cell array and that behavior is undefined.

John W. Eaton <jwe>
Project Administrator
Fri 02 Dec 2011 10:30:48 AM UTC, original submission:

The following is an example of a structure that behaves badly when it has an empty cell within.

This submission will be a list of examples of this behavior, ending with one that causes a crash. The problem in all cases is that this particular structure does not behave as other structures.

Example 1
The structure has more fieldnames than fields:

Example 2
Interpretation terminates once the empty cell is encountered.

Example 3
Any member can be extracted from the structure without errors, but the result is undefined even for 'val.name' which should be an empty cell.

Normally you would get these errors

Example 4
From within an OCT-file, the underlying octave_value of this structure can not be extracted and causes a segmentation fault with core dump.

This crash can be avoided by checking the size of
... but the Octave Manual does not mention this, and I doubt many of us have implemented that check.

Henrik Alsing Friberg <hfriberg>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -unavailable- added by hardy (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by rik5 (Updated the item)
  • -unavailable- added by jordigh (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by hfriberg (Submitted the item)
  •  

    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 9 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 16 May 2015 07:02:21 PM UTCmtmillerPriority5 - Normal=>3 - Low
      Item GroupIncorrect Result=>Matlab Compatibility
      StatusNeed Info=>Confirmed
      Operating SystemGNU/Linux=>Any
    Tue 28 Jan 2014 04:35:59 AM UTCmtmillerDependencies-=>bugs #36003 is dependent
    Mon 27 Jan 2014 02:27:10 AM UTCmtmillerSeverity3 - Normal=>2 - Minor
      StatusNone=>Need Info
      Release3.4.2=>dev
    Thu 10 Oct 2013 07:17:42 PM UTCrik5Item GroupSegfault, Bus Error, etc.=>Incorrect Result

    Back to the top


    Powered by Savane 3.1-cleanup1