Index: [thread] [date] [subject] [author]
  From: Steve Cheng <elmert@ipoline.com>
  To  : ggi-develop@eskimo.com
  Date: Fri, 17 Jul 1998 13:12:10 -0400 (EDT)

Re: display-tile buglet

On Fri, 17 Jul 1998, Andrew Apted wrote:

> The problem appears to be something not-nice about sscanf.  In
> display/tile/visual.c there is :
> 
>     if(sscanf(args, "%d,%d,%d,%d,%n", &sx, &sy, &vx, &vy, &n)!=4)
> 
> The manpage for sscanf says that the number of successful conversions is
> returned.  What happens (I suspect) is that even missing the last comma
> still returns 4 -- but there really was an error and the %n never gets
> set (which shoots us off into lala land).

Actually this is correct behavior because the comma isn't counted as a
conversion.  Neither is %n, for that matter.

> Checking it now...
> 
> Yep, that was it.  Below is a patch that fixes the problem.  Steve, look
> alright to you ?

Another small problem that should also be fixed is whitespace handling
between the commas.  This is not difficult to do;

Replace the sscanf in your patch with this:

                if ((sscanf(args, "%d , %d , %d , %d %n", &sx, &sy,
                     &vx, &vy, &n) != 4) || (args+=n, *args != ',')) {

[manpage: White space (such as blanks, tabs, or newlines) in the format
       string match any amount of white space, including none, in the input. 
       Everything else matches only itself.  Scanning stops when an input
       character does not match such a format character.  Scan- ning also
       stops when an input conversion cannot be made (see below).]

Now, because of the quirk in sscanf you've mentioned, this won't handle
whitespace *after* the final comma (i.e. just before the target string
itself).  There are two possible solutions:

1)  Instead of skipping the comma with args++,

	do {
		args++;
	} while(*args!=' ');

2)  Fix it in display/common/parsing.c.  This is more clean, IMO.
	

Otherwise, your patch is okay.  I wouldn't know all these sscanf rules
anyway.  Please submit patches to Andy to go into stable.  Or should I do
it?

Unfortunately, I will be going to vacation tomorrow for 3 days, so I won't
be able to fix anything meanwhile.  Sorry.

--
Steve Cheng               

email: steve@ggi-project.org   
www: <http://shell.ipoline.com/~elmert/>;


Index: [thread] [date] [subject] [author]