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

Bug#413195: Variable junk and segfault with gettimeofday function



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;

}


Reply to: