[libvirt] [PATCH] build: trivial fix error: implicit declaration of function 'malloc'
eblake at redhat.com
Thu Nov 22 13:53:12 UTC 2012
On 11/22/2012 06:46 AM, Natanael Copa wrote:
>> If your headers are defining this in terms of malloc(), then IMHO,
>> the sched.h should be including stdlib.h on our behalf. IOW, I
>> think this is a bug in the c library headers
> You are right. uclibc does this:
> #if 0 /* in uClibc we use macros */
> extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
> extern void __sched_cpufree (cpu_set_t *__set) __THROW;
> # define __sched_cpualloc(cnt) ((cpu_set_t *)malloc(__CPU_ALLOC_SIZE(cnt)))
> # define __sched_cpufree(__set) free(__set)
> And since this is only a warning, I don't think its worth the effort.
And that's where you're wrong. Using malloc() without a prototype means
you are attempting to call 'int malloc(int)' instead of 'void
*malloc(size_t)'; and if sizeof(size_t)>sizeof(int) (as on most 64-bit
platforms), you have silently miscompiled. The warning exists for a
reason, and we only have K&R C to blame that this is just a warning
rather than a hard error by default (at least C++ did it right by
mandating it as a hard error).
Eric Blake eblake at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 619 bytes
Desc: OpenPGP digital signature
More information about the libvir-list