On Sun, May 07, 2006 at 06:18:27PM +1000, Andree Leidenfrost wrote:
> - replaced fgets with getline() to avoid static strings and thus 
>   overflows

Good point !

> I've done some more testing, valgrind is still happy, so I think this is
> as good as it gets at the moment. If there is anything that I've
> overloooked, please let me know. 

Well, in order just to be picky, I would declare each variable on a
single line (personal preference):

char   *token, *string = NULL, *pos, type;
=>
char *token;
char *string = NULL;
char *pos;
char *type;

I find it more readable IMHO.


Other point. I'm not sure of the usage of memove and the memory
management it implies.

I would rather do:

asprintf(&str2,pos); rather than memmove(string, pos, strlen(string));
potentially followed by paranoid_free(string);
string = str2;

if you find it more readable.

because I'm not not sure what will happen of the first part of the
string, when you will free string later on. I fear a memory leak again.

I'd prefer to create more tmp variables, it's more work, but it's more
convenient, and thus we know what we allocated, and what to free.
So in clear we should be able to deal nearly only with asprintf and
getline, as memory string functions. 
memcpy could still be used for structure copy, but that's another story.

I wonder if I'll not commit a first set of asprintf changes from trunk
to stable, now that we go to 2.2.0. WDYT ?
I can't merge the latest modifications as they do not work, but most of
first where working, and it could be time to migrate them from trunk to
stable. It wil also ease the use of trunk for dealing with the rest of
memory management, minimizing the time to merge the patches from stable
to trunk.

Also wouldn't getdelim be useful for what you try to do ?

Also in the man page of strtok:

BUGS
       Never use these functions.

WDYT ? ;-) (Again I fear the following free, will it free the whole
memory ? We need to pass to free the pointer to the begining of the
thestring allocated by asprintf or getline)

Maybe we should write our own mr_strtok function which will do it
correctly ?

That's where perl is so efficient compared to C :-(


I know I'm surely too picky (as usual) but memory management has been so
strangely handled in mondo, that I would like to change that.

OTOH, I still wonder whether we should write everything in C (when it's
mainly string management, perl is really much better)

Not to refrain you, but I think it's the right moment to consider that
quite important point, and agree on it before going further.

Waiting your opinion on this,
Greetings
Bruno.
-- 
Des infos sur la musique ancienne  -- http://www.musique-ancienne.org
Des infos sur les logiciels libres -- http://www.HyPer-Linux.org
Home, sweet musical Home -- Lover of Andromède, Béatrice, Early Music, 
Josquin, Linux, Mélisande, Recorder, and Ségolène (not in that order)

Reply via email to