Re: Administrivia: List Announcement

From: Luciano Miguel Ferreira Rocha (strange_at_nsk.no-ip.org)
Date: 05/14/03

  • Next message: Michael Wojcik: "FW: partial analysis of vulndev-1.c"
    Date: Wed, 14 May 2003 15:45:29 +0100
    To: vuln-dev@securityfocus.com
    
    

    On Tue, May 13, 2003 at 10:45:21AM -0700, Brian Hatch wrote:
    > And for goodness sake, let's cast things properly if you're going
    > to malloc, and for good form include the size of the element, even
    > when it's a char:
    >
    > char *buf1 = (char*)malloc( SIZE * sizeof(char) );
    No, bad idea.

    If malloc isn't defined, the compiler will cast an int to a pointer, which
    may not be the same size.

    If malloc is (well) defined, it returns a type of (void *), well casted to
    any pointer by the compiler.

    Regards,
    Luciano Rocha


  • Next message: Michael Wojcik: "FW: partial analysis of vulndev-1.c"

    Relevant Pages

    • Re: problem with memcpy and pointers/arrays confusion - again
      ... this second method is known as an explicit conversion, or cast. ... The cast, in effect, tells the compiler: ... the malloc function. ... function taking a size_t as a parameter and returning a void pointer (i.e. ...
      (comp.lang.c)
    • Re: about the array
      ... 3- If you cast to the wrong type by accident, ... are malloc and free. ... the compiler should issue a diagnostic - gcc ... unknown set of arguments, and return an int. ...
      (comp.lang.c)
    • Re: Why the compiler applies sign extension to unsigned data?
      ... I want the value of p to be made unsigned *before* the cast. ... want the cast to generate a sign extension. ... ULONG_PTR is ULONG and casting the pointer to ULONG_PTR first is the ... on the compiler and on the knowledge of the size of the ptr variable, ...
      (microsoft.public.development.device.drivers)
    • Re: Using malloc
      ... If compiling C code, ... however (and still using malloc versus new) will require you to do the ... the C language did not enjoy the void pointer. ... Because of this a cast was required: ...
      (alt.comp.lang.learn.c-cpp)
    • Re: why still use C?
      ... >>type of the object pointed to by a pointer differs from the type that I, ... >>the programmer, know to be the real type pointed at. ... When you're using implementation defined behaviour, the compiler ... I would argue that the malloc() is just such a case. ...
      (comp.lang.c)