Bug 129945 - returning pointer to local variable
Summary: returning pointer to local variable
Status: RESOLVED FIXED
Alias: None
Product: SUSE LINUX 10.0
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: Final
Hardware: All SuSE Linux 10.0
: P5 - None : Minor
Target Milestone: ---
Assignee: Dr. Werner Fink
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-21 10:02 UTC by David Binderman
Modified: 2005-10-21 13:09 UTC (History)
0 users

See Also:
Found By: Other
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.