Re: gettimeofday segfaults with malloc but not calloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 13 January 2009 11:30:02 Belisko Marek wrote:
> Hi,
>
> On Tue, Jan 13, 2009 at 10:51 AM, Henrik Austad <henrik@xxxxxxxxx> wrote:
> > I'm using gettimeofday to get the most accurate time from the kernel
> >
> > When I use calloc to create and initalize memory for the struct timeval
> > *tv, everything works fine:
> >
> > struct timeval *tv;
> > tv = (struct timeval *)calloc(1, sizeof(struct timeval));
> > if (!tv) {
> >  /* handle error... */
> >  exit
> > }
> > gettimeofday(tv);
>
> according http://dell5.ma.utexas.edu/cgi-bin/man-cgi?gettimeofday+2
> gettimeofday has 2 input agruments.
> I get you code and compile and works ok for both (mallo, calloc).

Indeed. Hmm, strange. I had 2 arguments and included /sys/time.h, but then it 
said something about functions with wrong number of arguments. Now I don't get 
that error.

Heh, a bit embarrasing this..

But I still don't understand why it works with 1 argument and calloc before 
malloc. 

Ah well, problem solved (by gray-blackish magic).

Thanks a lot!

-- 
Henrik

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux