Re: [ILUG] C string concat question ??

From: Smelly Pooh (plop at domain redbrick.dcu.ie)
Date: Fri 04 May 2001 - 10:35:40 IST


In reply to Dave Neary's flatulent wordings,
> Dave Neary wrote:
> > strcat((msg=strdup(strvar1),
> > (msg=realloc(msg,strlen(msg)+strlen(strvar2)+1))==NULL?
> > bad_stuff():msg),strvar2);
>
> works :) I was only confusing myself with the whole "order of
> evaluation" red herring, since the first arg doesn't go near the second
> arg. But anyone who ever used this should be shot :)

If order of evaluation was right to left however then you will be realloccing
an unallocated msg, strlen() msg which could lead to a seg fault if msg
doesn't point somewhere valid and generaly make things quite sucky



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:11 GMT