mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-15 07:00:05 -05:00
spa: fix integer overflows etc. in spa_pod_compare_value
Add macro SPA_CMP to do 3-way comparisons safely, and use it to avoid signed integer overflows. Fix also float/double comparisons (previously 0.1 == 0.8 since cast to return type int). Fix Id/Bool comparisons so they can return negative value.
This commit is contained in:
parent
b94d6e53a1
commit
a63aa6329b
3 changed files with 28 additions and 14 deletions
|
|
@ -186,6 +186,16 @@ struct spa_fraction {
|
|||
x; \
|
||||
})
|
||||
|
||||
/** 3-way comparison. NaN > NaN and NaN > finite numbers */
|
||||
#define SPA_CMP(a, b) \
|
||||
({ \
|
||||
__typeof__(a) _a = (a); \
|
||||
__typeof__(b) _b = (b); \
|
||||
(_a > _b) ? 1 : (_a == _b) ? 0 : (_a < _b) ? -1 \
|
||||
: (_a == _a) ? -1 : (_b == _b) ? 1 \
|
||||
: 1; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Return the address (buffer + offset) as pointer of \a type
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue