GNOME Bugzilla – Bug 552505
gcc attribute alloc_size markup
Last modified: 2009-01-18 17:27:59 UTC
Following patch adds gcc attribute alloc_size markup to libxml2 allocator functions. For at-compile-time known sized allocations the compiler tracks the size of the pointer and can utilize overflow checking in standard mem* and str* functions. This feature has appearewd with gcc 4.3
Created attachment 118826 [details] [review] libxml2-2.7.1-alloc_size.patch patch to add allocsize markup
Hi Marcus, okay that's interesting but I'm a bit confused: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html seems to indicate it's useful only if __builtin_object_size is being used, and I don't use it in libxml2 code, so I'm wondering a bit about the actual use of the patch just by itself. Could you explain a bit ? thanks, Daniel
what happens is that the memcpy() memmove() strcpy() etc. standard libc functions use __builtin_objectg_size() internally. So if you allocate a at compile time known sized buffer and use one of the mem* or str* functions with such a known sized destination buffer, it will check its size and abort() if the operation would overflow. Not sure though if you ever allocate compile-time-known sized buffers with those functions or if they are ever passed into mem* or str* functions.
Okay, applied thanks ! I had to also fix the apibuild generator to handle the new extension, but that looks fine and is now commited to SVN, thanks, Daniel