sscanf misses "0" conversion w/ "%i" at end of string

John W. Eaton jwe at bevo.che.wisc.edu
Mon Apr 14 12:29:31 CDT 2008


On 13-Apr-2008, Jaroslav Hajek wrote:

| thanks for the report. Attached is a fix changeset.
| 
| On Fri, Apr 11, 2008 at 6:50 PM,  <etienne at isr.ist.utl.pt> wrote:
| >   [a,b,c]=sscanf("0.0.0","%i.%i.%i","C")
| >
| >  Gives
| >
| >   a = 0
| >   b = 0
| >   c = [](0x0)
| >
| >  The problem is that c is not set. If the last character is not "0",
| >  or if there is some padding, then sscanf performs correctly.
| >
| 
| OK, this is fixed now.
| 
| >    ## Does not pick up malformed hex notation (bug or feature?)
| >    [a,b,c]=sscanf("0.0.0x","%i.%i.%i","C")
| >    a = 0
| >    b = 0
| >    c = [](0x0)
| >
| 
| Bug, because sscanf accepts this. Again, fixed.
| 
| >    ## I'd say bug! If I want to read a 0 followed by a x.
| >    [a,b,c]=sscanf("0.0.0xg","%i.%i.%ix","C")
| >    a = 0
| >    b = 0
| >    c = [](0x0)
| >
| 
| Yes. However, note that it probably does not work as you think. If you
| try your test program below with
|   char * s = "0.0.0xy1";
| and
|     n = sscanf (s, "%i.%i.%ixy%i", &a, &b, &c, &d);
| then d is *not* read  (at least on my system), but
|     n = sscanf (s, "%i.%i.%iy%i", &a, &b, &c, &d);
| works. It seems that sscanf simply accepts 0x as 0x0. The code is also
| simpler that way.

I applied the patch.

Thanks,

jwe


More information about the Bug-octave mailing list