This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/55791] New: gcc fails to detect wrong type in sizeof in malloc


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55791

             Bug #: 55791
           Summary: gcc fails to detect wrong type in sizeof in malloc
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dcb314@hotmail.com


Given the following code, culled from customer code,

# include <stdlib.h>

extern void g(char *);

void f()
{
    char *p;

    // wrong type in sizeof in malloc
    p = (char *) malloc( 10 * sizeof( char *));

    g(p);
}

gcc can't detect that the malloc line should be something closer to

    p = (char *) malloc( 10 * sizeof( char));

i.e. the type in the sizeof expression must be the same as (or 
at very least the same size as) the type of destination buffer.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]