problems with char * return from a function

Dan Hipschman dsh@linux.ucla.edu
Thu Jun 12 06:00:00 GMT 2008


On Wed, Jun 11, 2008 at 08:52:13PM -0400, Vardhan, Sundara (GE Infra, Energy) wrote:
> Hi All
> 
> I am calling a function x within strcpy as follows
> 
> strcpy(a,x("sample text","default text"));
> 
> x is defined as follows
> 
> char * x(char *m, char *n)
> {
> 	char *return_val=NULL;
> 	if (check m is in database)
> 		return_val=m;
> 	else
> 		return_val=n;
> 	return(return_val);
> }

I see no problem with this code and writing a testcase based on it works
for me.  I think your problem is elsewhere.  Can you boil this down to a
self-contained program, including main() and everything, that exhibits
the incorrect behavior, which we can compile and test ourselves?  If
this does not reveal your bug, please post it with the version of GCC
you are using as well.

Thanks,
Dan



More information about the Gcc-help mailing list