bugGNU Octave - Bugs: bug #42235, "invalid conversion from...

 
 

bug #42235: "invalid conversion from string to real scalar" with %c, %d, %f, etc.

Submitted by:  Guillaume <gyom>
Submitted on:  Tue 29 Apr 2014 02:45:15 PM UTC  
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  John W. Eaton <jwe>
Originator Name:  Guillaume Open/Closed:  Closed
Release:  dev Operating 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)

Tue 17 Feb 2015 11:35:09 PM UTC, comment #10:

Works for me. Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Tue 17 Feb 2015 06:31:28 AM UTC, comment #9:

I checked in some changes that I think fix the problems reported here and improve compatibility in a few other cases. I added a few tests, but more are probably needed.

http://hg.savannah.gnu.org/hgweb/octave/rev/3c3b9fce7d2b
http://hg.savannah.gnu.org/hgweb/octave/rev/928ecc95f395
http://hg.savannah.gnu.org/hgweb/octave/rev/17a7e9f26e50

John W. Eaton <jwe>
Project AdministratorIn charge of this item.
Mon 16 Feb 2015 05:39:36 PM UTC, comment #8:

Uh, nevermind that patch. It doesn't really do the right thing. I'll try to come up with a better solution. Apparently '%s' and '%c' conversions are supposed to do string conversions for any numeric value that is in the range of valid characters. For Matlab, that seems to be any integer value between 0 and intmax ('uint16') regardless of the storage type (int, double, whatever)

John W. Eaton <jwe>
Project AdministratorIn charge of this item.
Mon 16 Feb 2015 05:34:12 AM UTC, comment #7:

Please try the attached patch.

(file #33098)

John W. Eaton <jwe>
Project AdministratorIn charge of this item.
Wed 18 Jun 2014 12:55:04 PM UTC, comment #6:

I haven't looked through the relevant section in enough detail yet to wager any clarifications or guesses. But note that this bug is not limited to %c. It applies to all integer and floating point conversion formats when given a string argument, so all of the following should apparently be fixed: %c, %d, %i, %o, %u, %x, %X, %f, %e, %E, %g, and %G. All are working in 3.8 and not working on default. I've retitled to make sure that is not lost.

Mike Miller <mtmiller>
Project Administrator
Wed 18 Jun 2014 11:44:00 AM UTC, comment #5:

You're absolutely right.

I'm trying to find a fix for this but am still rather confused by the code.
Should the 'c' option handled separately here:
http://hg.savannah.gnu.org/hgweb/octave/rev/491b0adfec95#l1.292
so as not to perform any int or double conversion?

Guillaume <gyom>
Tue 17 Jun 2014 06:12:04 PM UTC, comment #4:

The following example in matlab shows that "%s" and "%c" are different:

The string 'abcd' is an array of characters. In Mike's test, all the characters are treated one after the other using the same format specifier. This behavior is true for all format specifiers except %s which is meant to handle multiple characters at the same time [1].

[1] http://www.mathworks.fr/fr/help/matlab/ref/sscanf.html

Pantxo Diribarne <pantxo>
Project Member
Tue 17 Jun 2014 05:24:26 PM UTC, comment #3:

The error is indeed a consequence of this change:

http://hg.savannah.gnu.org/hgweb/octave/rev/491b0adfec95#l1.295

Given MATLAB behaviour, it seems that %c should be handled as if it was %s. Would you agree?

Guillaume <gyom>
Wed 30 Apr 2014 07:24:10 AM UTC, comment #2:

On a pretty old Matlab version (r2008b):

Pantxo Diribarne <pantxo>
Project Member
Wed 30 Apr 2014 02:01:04 AM UTC, comment #1:

Confirmed. I have not bisected but this is likely due to this change (mentioned in NEWS on the default branch btw):

http://hg.savannah.gnu.org/hgweb/octave/rev/491b0adfec95

And obviously you meant printf or sprintf in your example, right? So does Matlab do the following:

? What about the following?

Mike Miller <mtmiller>
Project Administrator
Tue 29 Apr 2014 02:45:15 PM UTC, original submission:

I've just recompiled a fresh version of the dev branch and I now get errors each time a %s type is used in a format specification:

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #33098:  diffs.txt added by jwe (4KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by gyom (Submitted the item)
  •  

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

    Only project members can vote.

     

     

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-02-17 rik5 StatusReady For Test => Fixed
        Open/ClosedOpen => Closed
    2015-02-17 jwe StatusPatch Submitted => Ready For Test
    2015-02-16 jwe StatusConfirmed => Patch Submitted
    2015-02-16 jwe Attached File- => Added diffs.txt, #33098
    2015-02-13 jwe Assigned toNone => jwe
    2014-06-18 mtmiller Summary"invalid conversion from string to real scalar" with %c => "invalid conversion from string to real scalar" with %c, %d, %f, etc.
    2014-05-01 mtmiller StatusNeed Info => Confirmed
        Operating SystemGNU/Linux => Any
    2014-04-30 mtmiller StatusNone => Need Info

    Back to the top


    Powered by Savane 3.4