linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn@gclements.plus.com>
To: Amit Dang <amit_dang@intersolutions.stpn.soft.net>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Issue "address of local variable returned"
Date: Fri, 27 May 2005 17:09:21 +0100	[thread overview]
Message-ID: <17047.17969.471930.213042@gargle.gargle.HOWL> (raw)
In-Reply-To: <013a01c560fb$37b16e80$9736a8c0@ispl091>


Amit Dang wrote:

>     I am facing following issue
> (g++ compiler  "g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)" is being
> used for compilation.)
> 
> Following piece of code gives warning: "address of local variable `op'
> returned"

> #include<iostream>
> using namespace std;
> 
> struct s {
>     char op[24];
>     int j;
> };
> 
> char* fun()
> {
>     struct s op;
>     strcpy(op.op, "898898898\0");
>     return op.op;
> }
> 
> int main()
> {
>     cout << fun() << endl;
>     return 0;
> }

> But when the structure is change no warning is issued
> Following is the new structure

> struct s {
>         int j;
>         char op[24];
> };

> Obviously I know that "op.op" should not be returned.
> 
> g++ compiler  "g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)" is being
> used for compilation.

Consider filing a bug report or enhancement request with the GCC
developers.

Ultimately, a compiler can't warn about every possible problem with a
program. Although I can't see any reason why it would be hard to catch
the second case.

-- 
Glynn Clements <glynn@gclements.plus.com>

  parent reply	other threads:[~2005-05-27 16:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-25  7:27 Issue "address of local variable returned" Amit Dang
     [not found] ` <2ab8d39a05052610175e3d7018@mail.gmail.com>
2005-05-27  3:54   ` Amit Dang
2005-05-27 16:09 ` Glynn Clements [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-05-25  7:17 Amit Dang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17047.17969.471930.213042@gargle.gargle.HOWL \
    --to=glynn@gclements.plus.com \
    --cc=amit_dang@intersolutions.stpn.soft.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).