Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2002:
[Freeciv-Dev] Re: dynamic timeout (PR#1356)
Home

[Freeciv-Dev] Re: dynamic timeout (PR#1356)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Raimar Falke <rfalke@xxxxxxxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: dynamic timeout (PR#1356)
From: Mike Kaufman <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 7 Apr 2002 15:27:25 -0500

On Sun, Apr 07, 2002 at 09:48:24PM +0200, Raimar Falke wrote:
> On Sun, Apr 07, 2002 at 10:45:31AM -0500, Mike Kaufman wrote:
> > On Sun, Apr 07, 2002 at 02:50:40PM +0200, Raimar Falke wrote:
> > > > +***************************************************************/
> > > > +void get_args(char *str, char **args, int numargs)
> > > 
> > > Please pass in the maximum size.
> > 
> > I do not understand. str's maximum size? why? 
> > numargs should be <= the size of the args array. I don't see why we need
> > anything else. Please be explicit.
> 
> *rereading the patch* I misunderstood it. Neither the caller nor the
> callee allocate memory but the args pointers point into the original
> string. Uhhh. Such pointer aliasing should IMHO be avoided. This
> construct
> 
>    char str[MAX_LEN];
>    char *args[numargs];
> 
>    sz_strlcpy(str, buffer);
>    get_args(str, args, numargs);
> 
>    str[0]='x';
> 
> will also change args[0][0]. This isn't intuitive.

I want 1. a single call 2. that's easy to use. I suppose that you want
to start allocating memory for these pointers... My opinion is that
you're already taking a risk by changing str. If the coder screws himself
by changing str _after_ the call, that's his own damn fault.

Give me a better reason than "aliasing should IMHO be avoided".
The question is: are we ever going to depend on that memory staying
around? The answer is perhaps. I'll think about it.

> 
> > > > +{
> > > > +  int i, len;
> > > > +  bool quoted = FALSE;
> > > 
> > > What about single quoted. See cut_comment.
> > 
> > These are not analogous situations. cut_comment merely looks for paired
> > sets before it gets to the octothorp. Here we've got to keep track of
> > everything. Besides, I want to be able to create players like:
> > create "ain't I cool" "don't mess with me" 
> > which won't work if apostrophes are special. (of course we could expect
> > the user to \', but now we expect the user to use double quotes, either
> > way the user has some responsibility)
> 
> And want to allow a player name 'Joe "The Hammer" User'

I'm not sure that you know what kind of a nightmare you're getting
yourself into.

> 
> > what would be relatively easy would be to treat ' and " interchangably.
> > so "5' 'abc da' "4t" 'a s" returns 4 tokens. To actually treat ' and "
> > in a nested fashion would suck ass. I don't have the energy (ok, it
> > wouldn't be _that_ hard, but I still don't have the energy). I look forward 
> > to your implementation. Extend this one after it's in cvs.
> 
> No problem adding it before it goes into CVS.

hmmph

> 
> > 'cause we may get garbage on the sscanf and we want to protect the
> > original value. But we should get rid of val[4] in favor of a tmp var 
> > inside 
> > the for loop.
> 
> sscanf doesn't overwrite the parameter if no valid input is found (if
> it returns 0). So the tmp variable isn't need.

ok.

> 
>       Raimar
> 
> -- 
>  email: rf13@xxxxxxxxxxxxxxxxx
>  "This is Linux Country. On a quiet night, you can hear Windows reboot."


[Prev in Thread] Current Thread [Next in Thread]