Hi,

I am forwarding this issue I had with a compile warning when building libvirtd.

It turns out that sched.h uses malloc without including stdlib.h. This
results in a silent compiling error on 64 bit platforms.


Begin forwarded message:

Date: Thu, 22 Nov 2012 06:53:12 -0700
From: Eric Blake <ebl...@redhat.com>
To: Natanael Copa <nc...@alpinelinux.org>
Cc: "Daniel P. Berrange" <berra...@redhat.com>, libvir-l...@redhat.com
Subject: Re: [libvirt] [PATCH] build: trivial fix error: implicit declaration 
of function 'malloc'


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;
> #else
> # define __sched_cpualloc(cnt) ((cpu_set_t *)malloc(__CPU_ALLOC_SIZE(cnt)))

Ouch.

> # define __sched_cpufree(__set) free(__set)
> #endif
> 
> 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).

_______________________________________________
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to