Re: why the usage of gets() is dangerous.
- From: rlb@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos)
- Date: Thu, 22 Nov 2007 11:46:47 GMT
Tor Rustad <tor_rustad@xxxxxxxxxxx> wrote:
Richard Bos wrote:
Tor Rustad <tor_rustad@xxxxxxxxxxx> wrote:
His solution requires the use of "fat pointers", which are notMethinks, fat pointers break pointer arithmetic and thus require at
least a new language dialect.
No, they don't.
Hmm... what about volatile, extern and variable-length arrays?
Why should they be different?
Also, I expect GC's, to do low-level pointer magic.
But GC in itself breaks ISO C compatibility. GC introduces a new
dialect; fat pointers do not.
Pointer arithmetic beyond the bounds of an object has
undefined behaviour anyway,
Off-by-one is allowed, see e.g. response to DR #76 and DR #221.
Of course, but that still doesn't break fat pointers.
and within an object it works fine with fat
pointers. Adding an integer to a pointer is now a matter of adding it to
a single field of the pointer structure, rather than to a flat index,
but something similar is needed with, e.g., segmented architectures.
Well, it appears to me that that segmented architectures capable of C99,
might not be able to have 65535 bytes for an object, when using fat
pointers.
Why on earth not? For starters, who says that segments _must_ be 1980s
Intel 8088-compatible segments?
Also, the buffer passed to gets() may not be malloc'ed, but can be an
array, or even a sub-array.
So? A sub-array simply has it recorded, in its fat pointer data, that it
is a sub-array, and what of.
So... the compiler would generate instrumented code then, lots of
run-time checks!
Yes. That's most the point of fat pointers. They are generally used in
debugging implementations. I don't know of any normal C implementation
which uses them.
This is getting far to theoretical.. fat pointers make sense to me, *if*
C had such a new pointer type, else everyone need to use "the same"
compiler, or how do you suggest we link in libraries in practice?
You misunderstand. Fat pointers are not a new pointer type within ISO C.
Rather, they are a way to implement normal C pointers behind the scene.
And yes, you do need to link fat-pointer-compiled object files with
fat-pointer-compiled libraries; much as you need to link 64-bit object
files with 64-bit libraries, little-endian object files with little-
endian libraries, and on MS-DOS used to link large memory model object
files with large memory model libraries.
Richard
.
- Follow-Ups:
- Re: why the usage of gets() is dangerous.
- From: Chris Torek
- Re: why the usage of gets() is dangerous.
- From: CBFalconer
- Re: why the usage of gets() is dangerous.
- References:
- why the usage of gets() is dangerous.
- From: jayapal
- Re: why the usage of gets() is dangerous.
- From: Paul Hsieh
- Re: why the usage of gets() is dangerous.
- From: Malcolm McLean
- Re: why the usage of gets() is dangerous.
- From: Richard Heathfield
- Re: why the usage of gets() is dangerous.
- From: Malcolm McLean
- Re: why the usage of gets() is dangerous.
- From: CBFalconer
- Re: why the usage of gets() is dangerous.
- From: Keith Thompson
- Re: why the usage of gets() is dangerous.
- From: Tor Rustad
- Re: why the usage of gets() is dangerous.
- From: Richard Bos
- Re: why the usage of gets() is dangerous.
- From: Tor Rustad
- why the usage of gets() is dangerous.
- Prev by Date: Re: Defeating Optimisation for memcmp()
- Next by Date: Re: Defeating Optimisation for memcmp()
- Previous by thread: Re: why the usage of gets() is dangerous.
- Next by thread: Re: why the usage of gets() is dangerous.
- Index(es):
Relevant Pages
|