Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: free a pointer and have it point to NULL |
| Date | 2014-04-29 21:29 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ljp5ji$6k8$1@speranza.aioe.org> (permalink) |
| References | (1 earlier) <lny4yxvydz.fsf@nuthaus.mib.org> <ljo1b6$rba$1@news.albasani.net> <ljob8f$f8i$1@dont-email.me> <535FD623.5000200@verizon.net> <viqvl9he4oah9fqr5n1fjmlfac17q1mv0k@4ax.com> |
Robert Wessel <robertwessel2@yahoo.com> wrote: > On Tue, 29 Apr 2014 12:41:07 -0400, James Kuyper > <jameskuyper@verizon.net> wrote: (snip) >>I left out a key step: on such systems it is often the case that loading >>an invalid into an address register is sufficient to cause your program >>abort. Dereferencing the pointer isn't necessary. This is a safety >>measure: the designers felt that any program written badly enough to >>treat an invalid address as if were a valid one, is sufficiently >>dangerous that it's safest to have a policy of stopping such programs as >>soon as possible. More specifically, the way x86 processors starting with the 80286 work, is that when you load a segment selector into a segment register, the processor also loads a segment descriptor from the appropriate entry in a descriptor table. If the descriptor is invalid, an interrupt occurs. > While not specifically a C example, we supported the Realia Cobol > compiler in the 16-bit era, and on protected mode systems, you'd have > exactly that problem. C compilers I know tend to avoid loading segment registers until they are pretty much ready to use them. For example, pointer assignment and pointer comparison are not done using a segment register. (I don't believe that there are compare instructions for segment registers. Assignment could be done through load and store, though.) > Cobol is mostly pass-by-reference (in those days it was all > pass-by-ref, there is some pass-by-value in the modern standards), and > the Realia calling convention put the (pointers to the) first two > parameters in DS:SI and ES:DI. Merely calling a subroutine with a > pointer to storage that had been returned to the OS would cause an > abend when the caller tried to load the appropriate segment register. There have been many systems where you could load from any memory address, such as real mode MS-DOS. Some programmers for those systems tend to ignore fetch from bad addresses, such as past the end of arrays. (In most cases, just after the end of an array is still part of your address space.) Much code for languages that don't require short-circuit IF evaluation works because the out of bounds fetch doesn't cause any problems. And, by the way, all the segment selector logic is still in current, and likely future, x86 processors. It isn't some strange system that died out years ago, now only found in a museum. (But there are some of those, too.) -- glen
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
free a pointer and have it point to NULL G G <gdotone@gmail.com> - 2014-04-22 14:22 -0700
Re: free a pointer and have it point to NULL James Kuyper <jameskuyper@verizon.net> - 2014-04-22 17:32 -0400
Re: free a pointer and have it point to NULL G G <gdotone@gmail.com> - 2014-04-22 14:36 -0700
Re: free a pointer and have it point to NULL Keith Thompson <kst-u@mib.org> - 2014-04-22 14:37 -0700
Re: free a pointer and have it point to NULL Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-04-29 13:10 +0200
Re: free a pointer and have it point to NULL Richard <rgrdev_@gmail.com> - 2014-04-29 13:14 +0200
Re: free a pointer and have it point to NULL Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-04-29 13:19 +0100
Re: free a pointer and have it point to NULL Kaz Kylheku <kaz@kylheku.com> - 2014-04-29 13:57 +0000
Re: free a pointer and have it point to NULL Kaz Kylheku <kaz@kylheku.com> - 2014-04-29 13:43 +0000
Re: free a pointer and have it point to NULL James Kuyper <jameskuyper@verizon.net> - 2014-04-29 09:59 -0400
Re: free a pointer and have it point to NULL Keith Thompson <kst-u@mib.org> - 2014-04-29 07:58 -0700
Re: free a pointer and have it point to NULL Keith Thompson <kst-u@mib.org> - 2014-04-29 11:50 -0700
Re: free a pointer and have it point to NULL James Kuyper <jameskuyper@verizon.net> - 2014-04-29 15:47 -0400
Re: free a pointer and have it point to NULL James Kuyper <jameskuyper@verizon.net> - 2014-04-29 12:41 -0400
Re: free a pointer and have it point to NULL Robert Wessel <robertwessel2@yahoo.com> - 2014-04-29 13:15 -0500
Re: free a pointer and have it point to NULL glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-29 21:29 +0000
Re: free a pointer and have it point to NULL glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-29 15:26 +0000
Re: free a pointer and have it point to NULL jt@toerring.de (Jens Thoms Toerring) - 2014-04-22 21:43 +0000
Re: free a pointer and have it point to NULL Keith Thompson <kst-u@mib.org> - 2014-04-22 14:53 -0700
Re: free a pointer and have it point to NULL Öö Tiib <ootiib@hot.ee> - 2014-04-24 00:38 -0700
Re: free a pointer and have it point to NULL James Kuyper <jameskuyper@verizon.net> - 2014-04-24 07:52 -0400
Re: free a pointer and have it point to NULL <william@wilbur.25thandClement.com> - 2014-04-24 16:13 -0700
Re: free a pointer and have it point to NULL Ian Collins <ian-news@hotmail.com> - 2014-04-25 12:02 +1200
Re: free a pointer and have it point to NULL <william@wilbur.25thandClement.com> - 2014-04-24 22:03 -0700
Re: free a pointer and have it point to NULL Ian Collins <ian-news@hotmail.com> - 2014-04-25 17:22 +1200
Re: free a pointer and have it point to NULL <william@wilbur.25thandClement.com> - 2014-04-24 23:00 -0700
Re: free a pointer and have it point to NULL Öö Tiib <ootiib@hot.ee> - 2014-04-27 08:32 -0700
Re: free a pointer and have it point to NULL Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2014-04-22 16:19 -0600
Re: free a pointer and have it point to NULL Kaz Kylheku <kaz@kylheku.com> - 2014-04-22 22:41 +0000
Re: free a pointer and have it point to NULL Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2014-04-22 18:17 -0600
Re: free a pointer and have it point to NULL Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2014-04-24 08:48 -0600
non-NULL pointers which have the value 0 (Was: Re: free a pointer and have it point to NULL) Andrew Cooper <root@127.0.0.1> - 2014-04-23 03:28 +0100
Re: non-NULL pointers which have the value 0 (Was: Re: free a pointer and have it point to NULL) Kaz Kylheku <kaz@kylheku.com> - 2014-04-23 04:37 +0000
Re: non-NULL pointers which have the value 0 glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-23 06:14 +0000
Re: free a pointer and have it point to NULL Kaz Kylheku <kaz@kylheku.com> - 2014-04-22 22:18 +0000
Re: free a pointer and have it point to NULL Michael Angelo Ravera <maravera@prodigy.net> - 2014-05-03 01:00 -0700
csiph-web