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


Groups > comp.lang.c > #66981

Re: I want to ask a question...

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: I want to ask a question...
Date 2015-08-08 01:37 +0100
Organization A noiseless patient Spider
Message-ID <87vbcq4nuf.fsf@bsb.me.uk> (permalink)
References (1 earlier) <87pp2y7wl7.fsf@gmail.com> <lnmvy2g291.fsf@kst-u.example.com> <mq3cqv$7el$1@speranza.aioe.org> <lnio8qfyr7.fsf@kst-u.example.com> <mq3f0j$bgp$1@speranza.aioe.org>

Show all headers | View raw


glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:

> Keith Thompson <kst-u@mib.org> wrote:
>
> (snip regarding references, even without dereferencing, pointers
> to unallocated memory.)
> (then I wrote)
>
>>> That is true, but even on systems where it could cause problems,
>>> compilers try to avoid it.
>
>>> For protected mode 80286, loading a segment selector register
>>> also loads the corresponding segment descriptor. That operation
>>> will fail if the desriptor isn't valid. (0 is a special null
>>> segment selector that doesn't load a descriptor.)
>
>>> In copying pointers, compilers will normally not load a segment
>>> selector into a segment register, but will either use normal 
>>> registers or other ways to move data. 
>> [...]
>  
>> It's also one of those cases where even if the behavior *weren't*
>> undefined, it would still be a good idea to avoid it.
>
> Yes. But even so, it might surprise someone.
>  
>> Once you've passed a pointer to free(), there's not much reason to look
>> at its value again.  If your program reads a pointer value after passing
>> it to free(), it's most likely because of a logical error in the program
>> (unless you're just doing it to see what happens).
>
> OK, consider an array of pointers, some of which might not point
> to anything (yet), or might point to free()'d memory. Now, consider
> making a copy of that array. Even if you know that the program only
> dereferences pointers to actual allocated memory, it might not be
> so easy to avoid copying them.
>
> I presume you are still not allowed to copy them with memcpy(),

I can't see why.  I think you can copy the bytes of any object without a
problem.

Further, I think you could wrap the array of pointers in a struct and
copy it by assignment because a struct (or union) itself is never a trap
representation, no matter what the component objects might be.

<snip>
-- 
Ben.

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


Thread

Re: I want to ask a question... Gareth Owen <gwowen@gmail.com> - 2015-08-07 20:00 +0100
  Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-07 19:04 +0000
  Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-07 15:30 -0700
    Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-07 22:52 +0000
      Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-07 16:46 -0700
        Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-07 23:29 +0000
          Re: I want to ask a question... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-08 01:37 +0100
          Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-07 18:55 -0700
            Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-08 05:51 +0000
              Re: I want to ask a question... Robert Wessel <robertwessel2@yahoo.com> - 2015-08-08 01:44 -0500
    Re: I want to ask a question... Ken Brody <kenbrody@spamcop.net> - 2015-08-10 12:46 -0400
    Re: I want to ask a question... supercat@casperkitty.com - 2015-08-19 16:43 -0700
      Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-19 18:09 -0700
        Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-20 01:00 +0000
          Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-19 20:25 -0700
            Re: I want to ask a question... supercat@casperkitty.com - 2015-08-20 08:15 -0700
              Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-20 11:38 -0700
                Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-20 18:47 +0000
                Re: I want to ask a question... supercat@casperkitty.com - 2015-08-20 14:01 -0700
            Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-20 16:43 +0000
              Re: I want to ask a question... James Kuyper <jameskuyper@verizon.net> - 2015-08-20 13:02 -0400
                Re: I want to ask a question... Tonton Th <tTh@nowhere.invalid> - 2015-08-20 17:40 +0000
                Re: I want to ask a question... James Kuyper <jameskuyper@verizon.net> - 2015-08-20 15:27 -0400
                Re: I want to ask a question... David Brown <david.brown@hesbynett.no> - 2015-08-20 22:58 +0200
                Re: I want to ask a question... James Kuyper <jameskuyper@verizon.net> - 2015-08-20 23:24 -0400
                Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-21 06:19 +0000
                Re: I want to ask a question... Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-08-21 09:20 -0600
                Re: I want to ask a question... supercat@casperkitty.com - 2015-08-22 12:25 -0700
                Re: I want to ask a question... Robert Wessel <robertwessel2@yahoo.com> - 2015-08-23 01:33 -0500
                Re: I want to ask a question... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-20 19:28 +0000
              Re: I want to ask a question... Keith Thompson <kst-u@mib.org> - 2015-08-20 12:11 -0700
          Re: I want to ask a question... David Brown <david.brown@hesbynett.no> - 2015-08-20 10:02 +0200
        Re: I want to ask a question... raltbos@xs4all.nl (Richard Bos) - 2015-08-22 13:42 +0000
          Re: I want to ask a question... supercat@casperkitty.com - 2015-08-22 12:23 -0700

csiph-web