[PR 17] GRETH: Fixed autonego timeout overflow problem
Ralf Corsepius
ralf.corsepius at rtems.org
Tue Mar 20 17:09:57 UTC 2012
On 03/20/2012 08:51 AM, Daniel Hellstrom wrote:
> Hello Ralf,
>
> The problem was first reported by Joris, please see BUG 1465.
>
> - msecs =
> (tnow.tv_sec-tstart.tv_sec)*1000+(tnow.tv_usec-tstart.tv_usec)/1000;
> + msecs =
> (int)(tnow.tv_sec-tstart.tv_sec)*1000+((int)tnow.tv_usec-(int)tstart.tv_usec)/1000;
>
>
> The seconds part is no problem. If (tstart.tv_usec > tnow.tv_usec) will
> be negative, but since the variables are unsigned a underflow will
> result in a very long msecs timeout.
Do I understand this correctly, your problem is msecs being unsigned,
which means it can't take a negative time, the case which would happen
if (tstart > tnow)?
In this case, I'd propose to introduce a signed temporary variable to
take the substraction's result and to special-case negative substraction
results later on.
Rough outline:
long _msecs =
(tnow.tv_sec-tstart.tv_sec)*1000+(tnow.tv_usec-tstart.tv_usec)/1000;
if (_msecs >= 0 ) {
msecs = _msecs;
} else {
msecs = 0; /* or whatever might be suitable */
}
Ralf
More information about the devel
mailing list