[comp.lang.c] Strcpy fun w/ Ultrix

tim@scsmo1.UUCP (04/27/89)

I ran accross a problem with strcpy in ultrix, for some reason it will
not return its first argument.  This is something like the "buged" code:
x->name=strcpy(malloc(strlen(in)+1),in);
The solution was:
strcpy(x->name=malloc(strlen(in)+1),in);

I was under the impression that strcpy will copy its first argument and
it does most of the time.  I have never run into this problem before, is
it common?  The thing that strcpy was returing was in a different section
of prevously malloc'ed memory and the strings do not overlap.

tim hogard
uunet!worlds!gensis!hogard	/* new address */
"Ultrix will drive you to drink!"

trebor@biar.UUCP (Robert J Woodhead) (04/29/89)

In article <9300002@scsmo1.UUCP> tim@scsmo1.UUCP writes:
>The solution was:
>strcpy(x->name=malloc(strlen(in)+1),in);

Er, does Ultrix have _strdup_?  You could just say:

	x->name=strdup(in);

-- 
Robert J Woodhead, Biar Games, Inc.  ...!uunet!biar!trebor | trebor@biar.UUCP
"The NY Times is read by the people who run the country.  The Washington Post
is read by the people who think they run the country.   The National Enquirer
is read by the people who think Elvis is alive and running the country..."

gwyn@smoke.BRL.MIL (Doug Gwyn) (04/29/89)

In article <9300002@scsmo1.UUCP> tim@scsmo1.UUCP writes:
>I ran accross a problem with strcpy in ultrix, for some reason it will
>not return its first argument.

Did you remember to #include <string.h> to declare the function?

bobg+@andrew.cmu.edu (Robert Steven Glickstein) (05/02/89)

> Excerpts from ext.nn.comp.lang.c: 27-Apr-89 Strcpy fun w/ Ultrix
> tim@scsmo1.UUCP (618)


> I ran accross a problem with strcpy in ultrix, for some reason it will
> not return its first argument.  This is something like the "buged" code:
> x->name=strcpy(malloc(strlen(in)+1),in);
> The solution was:
> strcpy(x->name=malloc(strlen(in)+1),in);

Danger, Will Robinson!  Bad programming style alert!

Do you WANT to dump core if malloc returns NULL?

-Bob Glickstein

nevin1@ihlpb.ATT.COM (Liber) (05/03/89)

In article <cYLAeIy00Vsn02rps8@andrew.cmu.edu> bobg+@andrew.cmu.edu (Robert Steven Glickstein) writes:
|> Excerpts from ext.nn.comp.lang.c: 27-Apr-89 Strcpy fun w/ Ultrix tim@scsmo1.UUCP (618)

|> strcpy(x->name=malloc(strlen(in)+1),in);

|Bad programming style alert!

|Do you WANT to dump core if malloc returns NULL?

Sometimes this leads to a better chance of recovery than some of the
other ways I've seen programs handle this situation (such as not being
able to do anything at all, for instance).  All things considered, I
would rather have a graceful recovery.

Oh, well.  
-- 
 _ __	NEVIN ":-)" LIBER  nevin1@ihlpb.ATT.COM  (312) 979-4751  IH 4F-410
' )  )			 "I will not be pushed, filed, stamped, indexed,
 /  / _ , __o  ____	  briefed, debriefed or numbered!  My life is my own!"
/  (_</_\/ <__/ / <_	As far as I know, these are NOT the opinions of AT&T.