mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-04-27 06:46:48 -04:00
spa: add and use spa_overflow macros
This commit is contained in:
parent
84f8230a47
commit
0f8d5c6e57
16 changed files with 149 additions and 50 deletions
40
spa/include/spa/utils/overflow.h
Normal file
40
spa/include/spa/utils/overflow.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* Simple Plugin API */
|
||||
/* SPDX-FileCopyrightText: Copyright © 2026 Wim Taymans */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#ifndef SPA_UTILS_OVERFLOW_H
|
||||
#define SPA_UTILS_OVERFLOW_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Check for addition overflow
|
||||
*
|
||||
* Computes \a a + \a b and stores the result in \a *res.
|
||||
* \return true if the addition overflowed, false otherwise
|
||||
*/
|
||||
#define spa_overflow_add(a, b, res) __builtin_add_overflow(a, b, res)
|
||||
|
||||
/**
|
||||
* \brief Check for subtraction overflow
|
||||
*
|
||||
* Computes \a a - \a b and stores the result in \a *res.
|
||||
* \return true if the subtraction overflowed, false otherwise
|
||||
*/
|
||||
#define spa_overflow_sub(a, b, res) __builtin_sub_overflow(a, b, res)
|
||||
|
||||
/**
|
||||
* \brief Check for multiplication overflow
|
||||
*
|
||||
* Computes \a a * \a b and stores the result in \a *res.
|
||||
* \return true if the multiplication overflowed, false otherwise
|
||||
*/
|
||||
#define spa_overflow_mul(a, b, res) __builtin_mul_overflow(a, b, res)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SPA_UTILS_OVERFLOW_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue