[En-Nut-Discussion] NutSleep Overflow Fix

Ole Reinhardt ole.reinhardt at embedded-it.de
Fri Jan 8 23:44:03 CET 2016


Hi All,

while cleaning my unread mails on the mailinglist, I stumbled uppon this
mail from Bob Wirka, who found an overflow problem with timeouts >
2^32-1 ms.

This issue just had been fixed on several architectures with Haralds
patch in r2964. I now applied it in r6267 to all further architectures,
where it still was missing (arm, cortex-m, coldfire).

Best regards,

Ole

Am 16.08.2013 um 17:25 schrieb Bob Wirka:
> Hello,
> 
> NutSleep(uint32_t ms) will not work properly if  'ms' is greater than 4,294,967 (0xffffffff / 10000)
> 
> This is because the calculation in NutTimerMillisToTicks() will overflow.
> 
> Below is my fix:
> 
> /*!
>  * \brief Calculate system ticks for a given number of milliseconds.
>  */
> uint32_t NutTimerMillisToTicks(uint32_t ms)
> {
>     unsigned long long        product;
> 
>     product = (unsigned long long)ms * (unsigned long long)NutGetTickClock();
>     return product / 1000;
> 
>     /*
>      * _RCW_: 16-Aug-2013 : This would overflow for ms values > 4,294,967, as
>      * the product of ms * NutGetTickClock() had to be <= 0xffff_ffff.
>      */
> //    return (ms * NutGetTickClock()) / 1000;
> }
> 
> Best regards,
> 
> Bob Wirka
> Realtime Control Works
> Janesville, WI
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
> 

-- 
kernel concepts GmbH            Tel: +49-271-771091-14
Sieghuetter Hauptweg 48         Mob: +49-177-7420433
D-57072 Siegen
http://www.embedded-it.de
http://www.kernelconcepts.de


More information about the En-Nut-Discussion mailing list