Jens Thoms Toerring wrote:
> paragon.john@[EMAIL PROTECTED]
wrote:
> > #include <stdio.h>
> > #include <fcntl.h>
>
> <fcntl.h> doesn't seem to be needed at all.
It's not a standard C header either.
> > int main()
> > {
> > int data_size = 1024*1024;
>
> Why not make that a 'size_t' so that you can be sure that
> the value actually fits in?
There is no guarantee that 1048576 will fit into a size_t.
> An int doesn't need to be able to hold more than 16 bits,
> which wouldn't be enough.
Since 1024 is just as int, then 1024*1024 can overflow,
irrespective of what you assign it to.
> > data_buf = (unsigned char *) valloc(data_size);
>
> Rather likely the problem is here. First of all, valloc()
> isn't a standard C function - and even the Linux man page
> describes it as "obsolete", so why don't you use malloc()?
>
> But the real problem is rather likely that there's no
> declaration for the valloc() function in scope since you
> didn't include <stdlib.h>.
Note that a mere delcaration is not sufficient. You may
need a prototype, especially if you're passing an int
argument for a size_t parameter.
<snip>
> So never cast the return value of malloc() (and other
> functions) unless you have a very good reason.
Prevention is better than cure. Requiring prototypes to
be in scope is a better suggestion IMO. Sadly, the option
actually breaks implementation conformance, although
I find the cost to be well worth it.
<snip>
--
Peter


|