mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04: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
|
|
@ -6,6 +6,7 @@
|
|||
#include <locale.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <valgrind/valgrind.h>
|
||||
|
||||
|
|
@ -150,6 +151,13 @@ PWTEST(utils_macros)
|
|||
pwtest_int_eq(SPA_CLAMP(-1, 1, 16), 1);
|
||||
pwtest_int_eq(SPA_CLAMP(8, 1, 16), 8);
|
||||
|
||||
pwtest_int_eq(SPA_CMP(INT64_MAX, INT64_MIN), 1);
|
||||
pwtest_int_eq(SPA_CMP(INT64_MIN, INT64_MAX), -1);
|
||||
pwtest_int_eq(SPA_CMP(INT64_MAX, INT64_MAX), 0);
|
||||
pwtest_int_eq(SPA_CMP(1, nan("")), -1);
|
||||
pwtest_int_eq(SPA_CMP(nan(""), 1), 1);
|
||||
pwtest_int_eq(SPA_CMP(nan(""), nan("")), 1);
|
||||
|
||||
/* SPA_MEMBER exists for backwards compatibility but should no
|
||||
* longer be used, let's make sure it does what we expect it to */
|
||||
pwtest_ptr_eq(SPA_MEMBER(ptr, 4, void), SPA_PTROFF(ptr, 4, void));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue