[cfe-dev] [PATCH RFC] add support to alloc_size attribute

Xi Wang xi.wang at gmail.com
Wed Feb 22 17:17:26 PST 2012


On Feb 22, 2012, at 8:10 PM, Eli Friedman wrote:
> +  unsigned* start = &AllocSizeArgs[0];
> +  unsigned size = AllocSizeArgs.size();
> +  llvm::array_pod_sort(start, start + size);
> 
> Don't you need to check for duplicates?  Also, for an alloc_size
> attribute which doesn't specify any indexes?
> 
> +    // Is the function argument an integer type?
> +    QualType T = getFunctionOrMethodArgType(D, x).getNonReferenceType();
> 
> I don't think you want to allow applying alloc_size to arguments of type "int&".
> 
> +    unsigned x = (unsigned) ArgNum.getZExtValue();
> 
> This is unsafe; there's no guarantee ArgNum fits into a 64-bit integer
> (which will cause an assert), and you're masking off the top 32 bits
> of that 64-bit integer without any additional checks.  You should
> perform the bounds checking on the APSInt, and then perform whatever
> conversion is necessary.  (And if this is copied from existing cod
> which does the same thing, please fix that as well.)

Thanks for the comments.  Yes, the code is basically a clone of
handleNonNullAttr().  Probably we need some helper function to
handle both cases. ;-)

- xi





More information about the cfe-dev mailing list