Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #103395

Re: Error message for a dangling pointer

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Manfred <noname@invalid.add>
Newsgroups comp.lang.c
Subject Re: Error message for a dangling pointer
Date Tue, 7 Feb 2017 18:42:15 +0100
Organization Aioe.org NNTP Server
Lines 32
Message-ID <o7d0tl$iis$2@gioia.aioe.org> (permalink)
References <dangling-pointers-20170207022252@ram.dialup.fu-berlin.de> <1btw8654l6.fsf@pfeifferfamily.net>
NNTP-Posting-Host Oxw+WWYQkT5mdTlKqxXz7g.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.c:103395

Show key headers only | View raw


On 2/7/2017 5:49 PM, Joe Pfeiffer wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
>>   For teaching purposes, I just wrote this program to show
>>   dangling pointers:
>>
<snip>
> I get the message in
> gcc (Debian 6.2.1-5) 6.2.1 20161124
> if I turn optimization -O1 on.  Also, without optimization the output is
> 27
> while with optimization it is
> 0
>
> I think we can see the code analysis that's leading to the conclusion
> that i is being used uninitialized (*p is being replaced by i, which is
> not even defined in the scope in which it is being used, let alone
> initialized).
>
> Even without the incorrect warning, I have to wonder how useful an
> example of a dangling pointer this would be for students.  Since I'd be
> *really* surprised to see an actual implementation really allocate a
> stack frame for the inner braces, the lecture would go sort of "see?  A
> dangling pointer.  And it does exactly the same thing it would have done
> if the pointer weren't dangling. That's why we should avoid dangling
> pointers" (and of course that's exactly what happens with gcc, without
> optimization).  Coax malloc() into reallocating space you can overwrite
> the contents or something....
>
Maybe a dangling pointer assigned (and lost) in a function call could be 
more explicit than with inner braces?
Eventually overwriting the stack frame with a second function call?

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Error message for a dangling pointer Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-02-07 09:49 -0700
  Re: Error message for a dangling pointer Manfred <noname@invalid.add> - 2017-02-07 18:42 +0100
    Re: Error message for a dangling pointer Manfred <noname@invalid.add> - 2017-02-07 19:09 +0100
    Re: Error message for a dangling pointer Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-02-07 21:20 -0700

csiph-web