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

Re: [Xen-devel] xl: Need help with overflow and error handling for vif rate support



Ian Campbell writes ("Re: [Xen-devel] xl: Need help with overflow and error 
handling for vif rate support"):
> On Tue, 2012-03-27 at 18:04 +0100, Mathieu Gagné wrote:
> > - How should I check for overflows when multiplying 2 uint64_t together?
> >    - I'm currently using math.h and log. Is it the correct approach?
> 
> You can check if A*B > UINT64_MAX by first checking
>       if B != 0 && A > UINT64_MAX/B
>               WOULD OVERFLOW

Another approach is to limit both A and B to less than
sqrt(UINT64_MAX), or to limit each of them to some smaller number.

Or use floating point, and do a check at the end when you convert it
back.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.