[comp.lang.c] Strcpy fun w/ UltrixREAD/NEW/FOLLOWUP

gsl3@csvax1.cs.tcd.ie (Generics Software Ltd.) (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)
> 
> 
>> 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

We should be so lucky, most of the ultrix implementation of string 
manipulation functions quite happily take a NULL pointer. I discovered
this when porting the code to a VMS machine. It was promptly sick when
passed the  NULL pointer. The moral of the story, check your return
values.

 Andy Trayler

 trayler@genrix.uucp  trayler@genrix.ie 
 ..!mcvax!einode!genrix!trayler

 | ... What, ME naive ! :^) |