Re: Is memcpy secure?

From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 01/30/04


Date: 30 Jan 2004 12:14:55 GMT

In <5c04bc56.0401291616.616c8411@posting.google.com> jjf@bcs.org.uk (J. J. Farrell) writes:

>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message news:<bvbo2b$ctu$1@canopus.cc.umanitoba.ca>...
>>
>> ANSI C -defines- long as being large enough to hold a pointer,
>> and guarantees that if you convert a pointer to a long and back
>> again (with no arithmetic operations on the long) then the result
>> will point to the original object.
>
>I don't believe it does. It allows pointers to be converted to
>integers in implementation-defined ways. It's not clear to me
>that it requires that a big enough integer exists (in C89 at
>least) and I'd welcome chapter and verse if it does.

Neither standard requires the existence of such an integer type.

C99 provides the *optional* intptr_t and uintptr_t aliases to the
signed and unsigned flavours of an integer type that is large enough
for the purpose and on which conversions back and forth reproduce
the original value. The aliases are optional because the underlying
types need not exist.

Dan

-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de


Relevant Pages

  • Re: Draft standards OK for new compiler and libc?
    ... the standard says that pointers can be converted to at least ... >>one integer type, which is implementation-specified, and back. ... Conversions that involve pointers (other than as permitted by the ... converted to a pointer. ...
    (comp.std.c)
  • Re: Is memcpy secure?
    ... >> and guarantees that if you convert a pointer to a long and back ... Neither standard requires the existence of such an integer type. ... for the purpose and on which conversions back and forth reproduce ... Dan Pop ...
    (comp.lang.c)
  • Re: How to know the memory pointed by a ptr is freed?
    ... >>the integer type is wide enough to hold a pointer. ... > group) that it required that there is ANY integer type large enough. ... Conversions that involve pointers (other than as permitted by the ... a cast from ptr vs. a memcpyfrom ptr". ...
    (comp.lang.c)
  • Re: main function address
    ... >> Can a pointer to a function be converted to an integer type such as ... Even on platforms defining the conversion between function ... Dan Pop ...
    (comp.lang.c)
  • Re: addresses and integers
    ... >> How do you check that the pointer is aligned for an integer access? ... Conversions between pointers and integers provide a fairly portable way ... Dan Pop ...
    (comp.lang.c)

Quantcast