mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
result: don't use undefined shift
Use a different way to generate the upper bits of the ASYNC mask instead of undefined shift as warned by sanitizer Add some unit test for this See #497
This commit is contained in:
parent
08ba6097a1
commit
948255f801
2 changed files with 20 additions and 1 deletions
|
|
@ -33,8 +33,8 @@ extern "C" {
|
||||||
#include <spa/utils/list.h>
|
#include <spa/utils/list.h>
|
||||||
|
|
||||||
#define SPA_ASYNC_BIT (1 << 30)
|
#define SPA_ASYNC_BIT (1 << 30)
|
||||||
#define SPA_ASYNC_MASK (3 << 30)
|
|
||||||
#define SPA_ASYNC_SEQ_MASK (SPA_ASYNC_BIT - 1)
|
#define SPA_ASYNC_SEQ_MASK (SPA_ASYNC_BIT - 1)
|
||||||
|
#define SPA_ASYNC_MASK (~SPA_ASYNC_SEQ_MASK)
|
||||||
|
|
||||||
#define SPA_RESULT_IS_OK(res) ((res) >= 0)
|
#define SPA_RESULT_IS_OK(res) ((res) >= 0)
|
||||||
#define SPA_RESULT_IS_ERROR(res) ((res) < 0)
|
#define SPA_RESULT_IS_ERROR(res) ((res) < 0)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <spa/utils/defs.h>
|
#include <spa/utils/defs.h>
|
||||||
|
#include <spa/utils/result.h>
|
||||||
#include <spa/utils/dict.h>
|
#include <spa/utils/dict.h>
|
||||||
#include <spa/utils/list.h>
|
#include <spa/utils/list.h>
|
||||||
#include <spa/utils/hook.h>
|
#include <spa/utils/hook.h>
|
||||||
|
|
@ -141,6 +142,23 @@ static void test_macros(void)
|
||||||
spa_assert(SPA_CLAMP(8, 1, 16) == 8);
|
spa_assert(SPA_CLAMP(8, 1, 16) == 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_result(void)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
spa_assert(SPA_RESULT_IS_OK(0) == true);
|
||||||
|
spa_assert(SPA_RESULT_IS_OK(1) == true);
|
||||||
|
spa_assert(SPA_RESULT_IS_ERROR(0) == false);
|
||||||
|
spa_assert(SPA_RESULT_IS_ERROR(1) == false);
|
||||||
|
spa_assert(SPA_RESULT_IS_ERROR(-1) == true);
|
||||||
|
spa_assert(SPA_RESULT_IS_ASYNC(-1) == false);
|
||||||
|
spa_assert(SPA_RESULT_IS_ASYNC(0) == false);
|
||||||
|
res = SPA_RESULT_RETURN_ASYNC(11);
|
||||||
|
spa_assert(SPA_RESULT_IS_ASYNC(res) == true);
|
||||||
|
spa_assert(SPA_RESULT_IS_ERROR(res) == false);
|
||||||
|
spa_assert(SPA_RESULT_IS_OK(res) == true);
|
||||||
|
spa_assert(SPA_RESULT_ASYNC_SEQ(res) == 11);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_dict(void)
|
static void test_dict(void)
|
||||||
{
|
{
|
||||||
struct spa_dict_item items[5] = {
|
struct spa_dict_item items[5] = {
|
||||||
|
|
@ -405,6 +423,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
test_abi();
|
test_abi();
|
||||||
test_macros();
|
test_macros();
|
||||||
|
test_result();
|
||||||
test_dict();
|
test_dict();
|
||||||
test_list();
|
test_list();
|
||||||
test_hook();
|
test_hook();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue