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


Groups > comp.lang.c > #103395

Re: Error message for a dangling pointer

From Manfred <noname@invalid.add>
Newsgroups comp.lang.c
Subject Re: Error message for a dangling pointer
Date 2017-02-07 18:42 +0100
Organization Aioe.org NNTP Server
Message-ID <o7d0tl$iis$2@gioia.aioe.org> (permalink)
References <dangling-pointers-20170207022252@ram.dialup.fu-berlin.de> <1btw8654l6.fsf@pfeifferfamily.net>

Show all headers | 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