Bug 129945

Summary: returning pointer to local variable
Product: [openSUSE] SUSE LINUX 10.0 Reporter: David Binderman <dcb314>
Component: BasesystemAssignee: Dr. Werner Fink <werner>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Minor    
Priority: P5 - None    
Version: Final   
Target Milestone: ---   
Hardware: All   
OS: SuSE Linux 10.0   
Whiteboard:
Found By: Other Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description David Binderman 2005-10-21 10:02:50 UTC
I just tried to compile package dvgt-3.51L3-1044 with the Intel C compiler 

It said

options.c(112): warning #1251: returning pointer to local variable

The source code is

  return (char *) &s;

I've checked the code and this one is most unusual. The code is certainly wrong.
Suggest change return type to void.
Comment 1 Dr. Werner Fink 2005-10-21 10:33:37 UTC
This should do the job

  return (Char*)&s[0];

at least for gcc 4.1. Remaining warnings

 g31:src # grep warning: /.build.log | wc -l
 332


Comment 2 David Binderman 2005-10-21 12:33:15 UTC
>This should do the job

I've had a think about it, and I don't think so.

Adding the trailing [ 0], as far as I know, doesn't help.

s is a local variable on the stack. 
Taking it's address as return value is surely a mistake, isn't it ?

I think my original advice still stands.

>332 remaining warnings.

Good job I'm only looking at the serious ones ;->
Comment 3 Dr. Werner Fink 2005-10-21 13:09:06 UTC
Hmmm ... gcc 4.1 reports the same error without '[0]' but
no one with the choosen element.  It seems that the gcc
reports the address of the String object specified to
stringcopy() .. what does the Intel compiler do in this
case?  Otherwise I could also use a pointer intstead of
using an array.