bugGNU Octave - Bugs: bug #56200, sscanf fourth output might be...

 
 

bug #56200: sscanf fourth output might be incorrect for decimal fields

Submitted by:  Felipe G. Nievinski <fgnievinski>
Submitted on:  Tue 23 Apr 2019 03:37:05 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  5.1.0 Operating System:  Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Thu 25 Apr 2019 06:23:46 AM UTC, comment #1:

Confirmed. It seems to be caused by the combination of all 3 of

1. the %d conversion specifier,
2. a field width on the %d conversion, and
3. the adjacent non-digit, non-space character

For example,

As you showed, if %f or %g is used instead, it works correctly.

If the field width is removed, it also works correctly

And if the integer is followed by a space instead of an alphabetic or punctuation character, it works correctly

Mike Miller <mtmiller>
Project Administrator
Tue 23 Apr 2019 03:37:05 PM UTC, original submission:

In Matlab, doing:

string = '1 9G02';
template = '%1d%3d';
size = 2;
[val, count, errmsg, nextpos] = sscanf (string, template, size)
display(['-' string(nextpos:end) '-'])

I get:

val =
1
9
count =
2
errmsg =
0×0 empty char array
nextpos =
5
-G02-

Whereas in Octave 5, I get a different result for output nextpos:

val =

1
9

count = 2
errmsg =
nextpos = 7
-2-

The only way to get the correct result for nextpos in Octave is replacing the last decimal field specification for a float:

string = '1 9G02';
template = '%1d%3f';
size = 2;
[val, count, errmsg, nextpos] = sscanf (string, template, size)
display(['-' string(nextpos:end) '-'])

val =

1
9

count = 2
errmsg =
nextpos = 5
-G02-

I seems the problem is caused by the adjacent literal character "G".

Felipe G. Nievinski <fgnievinski>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by fgnievinski (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-04-25 mtmiller CategoryNone => Octave Function
        Item GroupNone => Incorrect Result
        StatusNone => Confirmed
        Operating SystemMicrosoft Windows => Any

    Back to the top


    Powered by Savane 3.4