Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #15342
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Buffer access with bounds checking... |
| Date | 2012-08-31 18:48 -0400 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <k1rer3$imb$1@speranza.aioe.org> (permalink) |
| References | <86bccc99-b093-42c4-ae50-39c308b66254@p12g2000vbm.googlegroups.com> |
"Mark Wills" <markrobertwills@yahoo.co.uk> wrote in message news:86bccc99-b093-42c4-ae50-39c308b66254@p12g2000vbm.googlegroups.com... > While writing about memory buffer overruns in a different thread > earlier today, I was inspired to have a bash at writing some > code that would allow safe read/write access to memory buffers. > > I came up with the code and wonder if it could be simplified or > improved any. > > It's very simple. When a buffer is created, the first four cells > are reserved for the following: > * The pfa of the buffer (i'll explain in a minute) > * The size of the buffer in bytes > * The lowest legally accessible address > * The highest legally accessible address > The problem here is the same issue that C has with pointers. It's the same reason why Java removed pointers for safety. C has the issue of determining whether a pointer points to or into a valid C object, or not. If you have an address in Forth, you don't know if it points into a buffer, which buffer, or somewhere else, unless you check the ranges of _all_ known buffers. So, let's say you've got over 50 buffers and an address. Does the address point into a buffer and which one? You'll need a dictionary of buffer entries. You need to loop through all of them for each address to determine if the address is within the range of one of the buffers. As you demonstrated, this only works _if_ you already know which buffer an address points into. The other option is to not allow pointers to point into an object. Then, the pointer always points to the object's header, or to invalid data. But, that complicates accessing data within an object, such as a character from a string, or an item from a structure. Of course, if you don't realize it, what you're doing is implementing part of a type system. You're storing all the relevant info a compiler would need to check the type, but doing so just for your buffer. Rod Pemberton
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Buffer access with bounds checking... Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-31 06:51 -0700
Re: Buffer access with bounds checking... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-31 11:04 -0500
Re: Buffer access with bounds checking... Alex McDonald <blog@rivadpm.com> - 2012-08-31 09:20 -0700
Re: Buffer access with bounds checking... Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-31 12:57 -0700
Re: Buffer access with bounds checking... "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-31 18:46 -0400
Re: Buffer access with bounds checking... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-09-01 04:05 -0500
Re: Buffer access with bounds checking... "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-09-01 13:45 -0400
Re: Buffer access with bounds checking... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-09-02 04:19 -0500
Re: Buffer access with bounds checking... "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-09-02 16:15 -0400
Re: Buffer access with bounds checking... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-09-04 12:02 -0500
Re: Buffer access with bounds checking... Doug Hoffman <glidedog@gmail.com> - 2012-08-31 14:15 -0400
Re: Buffer access with bounds checking... Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-31 12:56 -0700
Re: Buffer access with bounds checking... Paul Rubin <no.email@nospam.invalid> - 2012-08-31 13:32 -0700
Re: Buffer access with bounds checking... Doug Hoffman <glidedog@gmail.com> - 2012-08-31 17:45 -0400
Re: Buffer access with bounds checking... Paul Rubin <no.email@nospam.invalid> - 2012-08-31 15:07 -0700
Re: Buffer access with bounds checking... Mark Wills <forthfreak@gmail.com> - 2012-09-01 00:49 -0700
Re: Buffer access with bounds checking... Paul Rubin <no.email@nospam.invalid> - 2012-09-01 14:06 -0700
Re: Buffer access with bounds checking... Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-09-02 04:21 -0500
Re: Buffer access with bounds checking... anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-09-02 10:27 +0000
Re: Buffer access with bounds checking... Doug Hoffman <glidedog@gmail.com> - 2012-09-01 06:59 -0400
Re: Buffer access with bounds checking... humptydumpty <ouatubi@gmail.com> - 2012-08-31 14:21 -0700
Re: Buffer access with bounds checking... "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-31 18:48 -0400
Re: Buffer access with bounds checking... Bernd Paysan <bernd.paysan@gmx.de> - 2012-09-01 01:41 +0200
Re: Buffer access with bounds checking... Bernd Paysan <bernd.paysan@gmx.de> - 2012-09-01 02:37 +0200
Re: Buffer access with bounds checking... mhx@iae.nl (Marcel Hendrix) - 2012-09-01 11:11 +0200
csiph-web