mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
internal: Add helper macro for checking multiply and add overflows
The macro does the two checks together so that it's obvious what we're checking as doing it in place is really unpleasant. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
3c5839973f
commit
23cb613606
@ -43,6 +43,17 @@
|
|||||||
|
|
||||||
#define VIR_INT_MULTIPLY_OVERFLOW(a,b) (G_UNLIKELY ((b) > 0 && (a) > G_MAXINT / (b)))
|
#define VIR_INT_MULTIPLY_OVERFLOW(a,b) (G_UNLIKELY ((b) > 0 && (a) > G_MAXINT / (b)))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIR_MULTIPLY_ADD_IS_OVERFLOW:
|
||||||
|
* @limit: maximum value of data type
|
||||||
|
* @value: current value
|
||||||
|
* @multiply: number @value is going to be multiplied by
|
||||||
|
* @add: number that will be added to @value after multiplication
|
||||||
|
*/
|
||||||
|
#define VIR_MULTIPLY_ADD_IS_OVERFLOW(limit, value, multiply, add) \
|
||||||
|
(G_UNLIKELY(((multiply) > 0 && (value) > (limit) / (multiply)) || \
|
||||||
|
((limit) - ((value) * (multiply)) < (add))))
|
||||||
|
|
||||||
/* The library itself is allowed to use deprecated functions /
|
/* The library itself is allowed to use deprecated functions /
|
||||||
* variables, so effectively undefine the deprecated attribute
|
* variables, so effectively undefine the deprecated attribute
|
||||||
* which would otherwise be defined in libvirt.h.
|
* which would otherwise be defined in libvirt.h.
|
||||||
|
Loading…
Reference in New Issue
Block a user