Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
Home

[Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Cc: Justin Moore <justin@xxxxxxxxxxx>, Freeciv Developers <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Split patch (was Re: [RFC PATCH] init_techs)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 28 Sep 2001 09:52:29 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Fri, Sep 28, 2001 at 12:00:07AM -0400, Ross W. Wetmore wrote:
> I like your statement of what you claim to be agreeing to followed
> by what you actually want to do in practice.
> 
> Why on earth would you handle the same buffer contents 3 times with
> all those allocation and free calls when you could do it once and
> let the caller deal with at most one extra copy depending on whether
> the original buffer or the results needed to be preserved.
> 
> But most of the time I would expect that no extra copies were required
> in the caller algorithms.
> 

> split should treat the buffer it was handed as working memory, return
> pointers into the parsed string elements, and let the caller deal with
> ALL memory issues.

Ok since there is so much resistance: we implement the strdup/free in
split if it turns out that every caller of split will copy the string
because it is needed later. Ok?

> >   {
> >      char *token;
> >      ....
> >      mystrlcpy(items[i],token,max_item_len);

> More unnecessary garbage, this one usually generates tons of memory leaks
> from absent minded programmers, or those that can't tell 5 levels up
> who allocated or should deallocate this. Especially bad for 1st or 2nd
> generation maintainers who never really wrote or dealt with this in the
> first place. VERY bad programming practice to put such things in utility
> routines.

You know what strlcpy is? It is just the safe version of strcpy. There
are no memory leaks here. The caller calls split like:

  char *string;
  char items[MAX_ITEMS][MAX_ITEM_LEN];

  split(...);

There just are no memory leaks possible.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "From what I am reading Win98 and NT5.0 will be getting rid of all that
  crap anyway. Seems that Microsoft has invented something called TCP/IP and
  another really revolutionary concept called DNS that eliminates the
  netbios crap too. All that arping from browsers is going to go away.
  I also hear rumors that they are on the verge of breakthrough discoveries
  called NFS, and LPD too. Given enough time and money, they might
  eventually invent Unix."
    -- George Bonser in linux-kernel


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