On 6 November 2017 at 17:41, Paolo Bonzini <pbonz...@redhat.com> wrote:
> What about
>
> #define type_max(t)                   \
>     ((t) -1 > 0                       \
>      ? (t)~0                          \
>      : (((t)1) <<                     \
>          (sizeof(t) * 8 - 1)) - 1)    \
>
> #define TIME_MAX type_max(time_t)
>
> ?  We don't need it to be a cpp constant, do we?  Or if we did, we could
> assume it to be signed, it's enough for the three users.

GCC doesn't like this phrasing, it complains
qmp.c: In function ‘qmp_expire_password’:
qmp.c:334:89: error: integer overflow in expression [-Werror=overflow]

because of the shift into the sign bit. Instead we can borrow the
TYPE_MAXIMUM macro from gnulib, which uses basically the same
approach but avoids the UB and the compiler warning. I'll send
a patch in a bit.

thanks
-- PMM

Reply via email to