Re: [spice v3] utils: Remove the LL suffix from NSEC_PER_SEC

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

 



On 6/25/19 7:35 PM, Francois Gouget wrote:
On Tue, 25 Jun 2019, Frediano Ziglio wrote:
[...]
     uint64_t foo = 1234;
     spice_debug("foo=%" PRId64, foo / NSEC_PER_SEC);
[...]
If you assume long long == 64 bit should not be a big problem
although you can still have the warning.

So, we all agree that the LL suffix is not good.
And we all agree that this patch fixes this issue.

Also if NSEC_PER_SEC is changed to be of type int64_t, then
there is no warning here.

So, the discussion is if the issue can be fixed differently,
with a prefix of (int64_t) or with INT64_C.


[...]


I'd very much prefer the cast to be in the expression rather than hidden
in some far away macro.

Is that true even if the cast is needed in all the expressions
that use this constant ?

Thanks,
    Uri.


For instance:

     int frames_count;
     ...

     if (duration > NSEC_PER_SEC * drawable->frames_count / MAX_FPS) {

Anyone checking this calculation would think that there is a risk of
overflow. And it's only when tracing NSEC_PER_SEC to utils.h that they
would discover that NSEC_PER_SEC forces 64 bit calculation.

At least this form is clear right away:

     if (duration > ((uint64_t)NSEC_PER_SEC) * drawable->frames_count / MAX_FPS) {

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]