spa: add and use spa_overflow macros

This commit is contained in:
Wim Taymans 2026-04-24 15:54:15 +02:00
parent 84f8230a47
commit 0f8d5c6e57
16 changed files with 149 additions and 50 deletions

View file

@ -39,6 +39,7 @@
#include <bluetooth/bluetooth.h>
#include <spa/utils/defs.h>
#include <spa/utils/overflow.h>
#include <spa/support/log.h>
#include "rate-control.h"
@ -107,9 +108,12 @@ static inline int spa_bt_decode_buffer_init(struct spa_bt_decode_buffer *this, s
this->frame_size = frame_size;
this->rate = rate;
this->log = log;
this->buffer_reserve = this->frame_size * reserve;
this->buffer_size = this->frame_size * quantum_limit * 2;
this->buffer_size += this->buffer_reserve;
if (spa_overflow_mul(this->frame_size, reserve, &this->buffer_reserve))
return -ENOMEM;
if (spa_overflow_mul(this->frame_size, quantum_limit, &this->buffer_size) ||
spa_overflow_mul(this->buffer_size, 2u, &this->buffer_size) ||
spa_overflow_add(this->buffer_size, this->buffer_reserve, &this->buffer_size))
return -ENOMEM;
this->corr = 1.0;
this->prev_match_rate = 1.0;
this->target = 0;

View file

@ -12,6 +12,7 @@
#include <spa/utils/list.h>
#include <spa/utils/string.h>
#include <spa/utils/overflow.h>
#define PW_TELEPHONY_SERVICE "org.pipewire.Telephony"
@ -1100,10 +1101,11 @@ telephony_ag_new(struct spa_bt_telephony *telephony, size_t user_data_size)
{
struct impl *impl = SPA_CONTAINER_OF(telephony, struct impl, this);
struct agimpl *agimpl;
size_t alloc_size;
spa_assert(user_data_size < SIZE_MAX - sizeof(*agimpl));
spa_assert(!spa_overflow_add(sizeof(*agimpl), user_data_size, &alloc_size));
agimpl = calloc(1, sizeof(*agimpl) + user_data_size);
agimpl = calloc(1, alloc_size);
if (agimpl == NULL)
return NULL;
@ -1334,10 +1336,11 @@ struct spa_bt_telephony_call *
telephony_call_new(struct spa_bt_telephony_ag *ag, size_t user_data_size)
{
struct callimpl *callimpl;
size_t alloc_size;
spa_assert(user_data_size < SIZE_MAX - sizeof(*callimpl));
spa_assert(!spa_overflow_add(sizeof(*callimpl), user_data_size, &alloc_size));
callimpl = calloc(1, sizeof(*callimpl) + user_data_size);
callimpl = calloc(1, alloc_size);
if (callimpl == NULL)
return NULL;