lchan->s and integer overflow

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Peter Stuge peter at stuge.se
Wed Mar 13 16:02:02 UTC 2013


Holger Hans Peter Freyther wrote:
> the easiest way to avoid the problem of the number to leave the range
> of 0 to radio_link_timeout is to use the OSMO_MAX and OSMO_MIN (now
> that these macros are fixed).
> 
> Underflow:
> lchan->s = OSMO_MAX(lchan->s - 1, 0);

It avoids the problem, but why is it safe?

The mere possibility that the counter can become negative suggests
an imbalance somewhere in the code - but I don't know if that's the
case, which is why I ask.


//Peter




More information about the OpenBSC mailing list