Date: Thu, 19 Jun 2008 16:37:30 +0200
From: address@hidden
Subject: [lwip-users] use of struct timeval in sys_jiffies, UNIX port
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes";
format="flowed"
My compiler complained about tv.tv_sec being used before it was
initialized, and upon inspection I must say I don't really understand
what is happening.
Depending on the compiler, isn't the value of tv_sec at best
initialized to zero, otherwise unpredictable? And the result from
gettimeofday is not used for anything?
From sys_arch.c, UNIX port, latest version in CVS.
unsigned long
sys_jiffies(void)
{
struct timeval tv;
unsigned long sec = tv.tv_sec;
long usec = tv.tv_usec;
gettimeofday(&tv,NULL);
if (sec >= (MAX_JIFFY_OFFSET / HZ))
return MAX_JIFFY_OFFSET;
usec += 1000000L / HZ - 1;
usec /= 1000000L / HZ;
return HZ * sec + usec;
}
Index: sys_arch.c
===================================================================
RCS file: /sources/lwip/contrib/ports/unix/sys_arch.c,v
retrieving revision 1.21
diff -u -5 -p -r1.21 sys_arch.c
--- sys_arch.c 30 May 2008 11:41:51 -0000 1.21
+++ sys_arch.c 19 Jun 2008 15:29:50 -0000
@@ -585,14 +585,16 @@ sys_arch_unprotect(sys_prot_t pval)
unsigned long
sys_jiffies(void)
{
struct timeval tv;
- unsigned long sec = tv.tv_sec;
- long usec = tv.tv_usec;
+ unsigned long sec;
+ long usec;