[torqueusers] A question on the attrlist_alloc function in attr_func.c

Prakash Velayutham velayups at email.uc.edu
Sat Jul 16 09:16:38 MDT 2005


I am going through torque source code for some reason and I
found this. I am not clear how this works. Can someone explain?

The attrlist_alloc function in attr_func.c file has this body.

svrattrl *attrlist_alloc(szname, szresc, szval)
        int szname;
        int szresc;
        int szval;
        register size_t tsize;
        svrattrl *pal;

        tsize = sizeof(svrattrl) + szname + szresc + szval;
        pal = (svrattrl *)malloc(tsize);
        if (pal == (svrattrl *)0)
                return ((svrattrl *)0);
#ifdef DEBUG
        memset(pal, 0, sizeof(svrattrl));

        CLEAR_LINK(pal->al_link);       /* clear link */
        pal->al_atopl.next = 0;
        pal->al_tsize = tsize;          /* set various string
sizes */
        pal->al_nameln = szname;
        pal->al_rescln = szresc;
        pal->al_valln  = szval;
        pal->al_flags  = 0;
        pal->al_op     = SET;
        pal->al_name = (char *)pal + sizeof (svrattrl);
        if (szresc)
                pal->al_resc = pal->al_name + szname;
                pal->al_resc = (char *)0;
        pal->al_value = pal->al_name + szname + szresc;
        return (pal);

The memset call is setting 52 bytes of memory area pointed to
by pal to 0. But pal is initially allocated only 4 bytes using
malloc. Isn't this overstepping memory?


More information about the torqueusers mailing list