lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: bug fix


From: Tony Mountifield
Subject: [lwip-users] Re: bug fix
Date: Thu, 9 Sep 2004 14:59:32 +0000 (UTC)

In article <address@hidden>,
K.J. Mansley <address@hidden> wrote:
> Thanks for your contribution!
> 
> Could you provide some more explanation about the problem and the fix
> please?  The use of unsigned arithmetic to do < and > comparisons is
> fairly standard.  In particular, examples of where the existing code
> gets it wrong would be very helpful.

Some compilers seem to think they can optimise "if ((a-b) < 0)" to be
"if (a < b)", which is not the same at all in the overflow case.

I've actually seen a more concise solution to this than the examples
below, which goes like this:

#define TCP_SEQ_LT(a,b)       ((((a)-(b)) & 0x80000000) != 0)
#define TCP_SEQ_GT(a,b)       ((((b)-(a)) & 0x80000000) != 0)
#define TCP_SEQ_GEQ(a,b)       ((((a)-(b)) & 0x80000000) == 0)
#define TCP_SEQ_LEQ(a,b)       ((((b)-(a)) & 0x80000000) == 0)

Cheers
Tony

> Thanks
> 
> Kieran
> 
> PS. Things such as this are generally best sent to one of the mailing
> lists rather than to me personally, as there are many more people
> involved in the project who might be interested or more able to help.
> 
> On Thu, 2004-09-09 at 06:51, Brett Jones wrote:
> > this code seems to fix a que full error that occurs durring large
> > transfers of data.
> >  
> > use it however you wish :)
> >  
> > //#define TCP_SEQ_LT(a,b)     ((S32)((a)-(b)) < 0)
> > //#define TCP_SEQ_LEQ(a,b)    ((S32)((a)-(b)) <= 0)
> > //#define TCP_SEQ_GT(a,b)     ((S32)((a)-(b)) > 0)
> > //#define TCP_SEQ_GEQ(a,b)    ((S32)((a)-(b)) >= 0)
> > S32 TCP_SEQ_LT( U32 a, U32 b )
> > {
> >  //determine if a is less than b
> >  if( a == b )
> >  {
> >   return FALSE;
> >  }
> >  if( a > b )
> >  {
> >   if( a-b <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return FALSE;
> >   }
> >   //rolled over
> >   return TRUE;
> >  }
> >  else
> >  {
> >   if( b-a <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return TRUE;
> >   }
> >   //rolled over
> >   return FALSE;
> >  }
> > }
> > S32 TCP_SEQ_LEQ( U32 a, U32 b )
> > {
> >  if( a == b )
> >  {
> >   return TRUE;
> >  }
> >  if( a > b )
> >  {
> >   if( a-b <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return FALSE;
> >   }
> >   //rolled over
> >   r eturn TRUE;
> >  }
> >  else
> >  {
> >   if( b-a <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return TRUE;
> >   }
> >   //rolled over
> >   return FALSE;
> >  }
> > }
> > S32 TCP_SEQ_GT( U32 a, U32 b )
> > {
> >  if( a == b )
> >  {
> >   return FALSE;
> >  }
> >  if( a > b )
> >  {
> >   if( a-b <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return TRUE;
> >   }
> >   return FALSE;
> >  }
> >  else
> >  {
> >   if( b-a <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return FALSE;
> >   }
> >   //rolled over
> >   return TRUE;
> >  }
> > }
> > S32 TCP_SEQ_GEQ( U32 a, U32 b )
> > {
> >  if( a == b )
> >  {
> >   return TRUE;
> >  }
> >  if( a > b )
> >  {
> >   if( a-b <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return TRUE;
> >   }
> >   //rolled over
> >   return FALSE;
> >  }
> >  else
> >  {
> >   if( b-a <= 0x7fffffff )
> >   {
> >    //no rollover
> >    return FALSE;
> >   }
> >   //rolled over
> >   return TRUE;
> >  }
> > }
> > 
> > 
> > 
> > ______________________________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail - You care about security. So do we.
> 
> 
> 
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users
> 


-- 
Tony Mountifield
Work: address@hidden - http://www.softins.co.uk
Play: address@hidden - http://tony.mountifield.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]