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

Bug#413195: marked as done (Variable junk and segfault with gettimeofday function)



Your message dated Sat, 03 Mar 2007 09:45:10 +0000
with message-id <1172915110.23836.9.camel@kaa.jungle.aubergine.my-net-space.net>
and subject line Bug#413195: Variable junk and segfault with gettimeofday function
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
package: libc6
version: 2.3.6.ds1-11

I incorrectly posted Bug#413078 against kernel, but had similar prob with old kernel too.

The bloated version works, but the simple one does not.  Any ideas why?

Man pages have:

PRINTF(3)
SYNOPSIS
       #include <stdio.h>

GETTIMEOFDAY(2)  
SYNOPSIS
       #include <sys/time.h>
       #include <time.h>

On a K8 machine:

andrewb@thot:~/public_html/c-run$ gcc -o gettimeofday_sane gettimeofday_sane.c 
andrewb@thot:~/public_html/c-run$ gcc -o gettimeofday_bloat gettimeofday_bloat.c 
andrewb@thot:~/public_html/c-run$ ./gettimeofday_sane 
18589.085472
andrewb@thot:~/public_html/c-run$ ./gettimeofday_bloat 
0xffdcdf58
1172905545==1172905545==1172905545
1172905545.972903

On a G4 machine:

andrewb@chrp:~/src$ gcc -o gettimeofday_sane gettimeofday_sane.c 
andrewb@chrp:~/src$ gcc -o gettimeofday_bloat gettimeofday_bloat.c 
andrewb@chrp:~/src$ ./gettimeofday_sane
Segmentation fault
andrewb@chrp:~/src$ ./gettimeofday_bloat
0x7ff20640
1172905674==1172905674==1172905674
1172905674.173928
/*#include <stdlib.h>*/
#include <stdio.h>
#include <sys/time.h>
#include <time.h>

int main()
{
	struct timeval *tp;
/*	struct timeval {
		unsigned long tv_sec;
		unsigned long tv_usec;
	} *tp;
	struct timeval {
		time_t		tv_sec;
		suseconds_t	tv_usec;
	} *tp;
	int j; */
	/* time_t tr, tr2, tr3;

	tr=time(0); */ /* BROKEN arg must be NULL */

	/* printf("%p\n",tp); */ /* says (nil) ! */

	/* tp->tv_sec=tr; */ /* segfaults even if not NULL */
/*
	j=gettimeofday(tp, (struct timezone *)0);
*/
	gettimeofday(tp, 0);

	/* tr3=time(&tr2);

	printf("%lu==%lu==%lu\n", tr, tr2, tr3); */

	printf("%lu.%06lu\n", tp->tv_sec, tp->tv_usec);
/*
	exit(0);
*/
	return 0;

}

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>

int main()
{
	struct timeval *tp;
/*	struct timeval {
		unsigned long tv_sec;
		unsigned long tv_usec;
	} *tp;
	struct timeval {
		time_t		tv_sec;
		suseconds_t	tv_usec;
	} *tp;
	int j; */
	time_t tr, tr2, tr3;

	tr=time(0); /* BROKEN arg must be NULL */

	printf("%p\n",tp); /* says (nil) ! */

	/* tp->tv_sec=tr; */ /* segfaults even if not NULL */
/*
	j=gettimeofday(tp, (struct timezone *)0);
*/
	gettimeofday(tp, 0);

	tr3=time(&tr2);

	printf("%lu==%lu==%lu\n", tr, tr2, tr3);

	printf("%lu.%06lu\n", tp->tv_sec, tp->tv_usec);

	exit(0);

	return 0;

}


--- End Message ---
--- Begin Message ---
On Sat, 2007-03-03 at 16:19 +0900, Andrew Buckeridge wrote:
> package: libc6
> version: 2.3.6.ds1-11
> 
> I incorrectly posted Bug#413078 against kernel, but had similar prob with old kernel too.
> 
> The bloated version works, but the simple one does not.  Any ideas why?

I'd suspect luck...

Your "sane" version (after stripping out all the commented out sections)
returns a constant value on i386. You are passing an uninitialised
pointer to gettimeofday() and additionally assuming that gettimeofday()
is always succeeding. That function is returning EFAULT here, which
would account for the segfaults you're seeing.

This version, on the other hand, works fine (ignoring the fact that it
doesn't cope with errors returned by gettimeofday()):

#include <stdio.h>
#include <sys/time.h>
#include <time.h>

int main()
{
        struct timeval tp;

        gettimeofday(&tp, 0);

        printf("%lu.%06lu\n", tp.tv_sec, tp.tv_usec);

        return 0;
}

Closing this non-bug.

Regards,

Adam

--- End Message ---

Reply to: