From 3af28af6ba71a8f7334539e720e112cb65dc06e3 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 29 May 2026 12:57:31 +0200 Subject: [PATCH] lib: return -ERANGE for hpointer/tstamp functions on overflow Signed-off-by: Jaroslav Kysela --- include/tinycompress/tinycompress.h | 2 ++ src/lib/compress.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index 74a7167..2fb6b0b 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -130,6 +130,7 @@ void compress_close(struct compress *compress); /* * compress_get_hpointer: get the hw timestamp * return 0 on success, negative on error + * returns -ERANGE if avail exceeds UINT_MAX; *avail is set to UINT_MAX * * @compress: compress stream on which query is made * @avail: buffer available for write/read, in bytes @@ -154,6 +155,7 @@ int compress_get_hpointer64(struct compress *compress, /* * compress_get_tstamp: get the raw hw timestamp * return 0 on success, negative on error + * returns -ERANGE if avail exceeds UINT_MAX; *samples is set to UINT_MAX * * @compress: compress stream on which query is made * @samples: number of decoded samples played diff --git a/src/lib/compress.c b/src/lib/compress.c index d73b171..bc41afc 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -208,8 +208,10 @@ int compress_get_hpointer(struct compress *compress, ret = compress->ops->get_hpointer(compress->data, &_avail, tstamp); if (ret >= 0) { - if (_avail > UINT_MAX) + if (_avail > UINT_MAX) { + ret = -ERANGE; _avail = UINT_MAX; + } *avail = (unsigned int)_avail; } return ret; @@ -229,8 +231,10 @@ int compress_get_tstamp(struct compress *compress, ret = compress->ops->get_tstamp(compress->data, &_samples, sampling_rate); if (ret >= 0) { - if (_samples > UINT_MAX) + if (_samples > UINT_MAX) { + ret = -ERANGE; _samples = UINT_MAX; + } *samples = (unsigned int)_samples; } return ret; -- 2.52.0