From: Jaroslav Kysela Date: Fri, 29 May 2026 10:57:31 +0000 (+0200) Subject: lib: return -ERANGE for hpointer/tstamp functions on overflow X-Git-Tag: v1.2.16~18 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=3af28af6ba71a8f7334539e720e112cb65dc06e3;p=tinycompress.git lib: return -ERANGE for hpointer/tstamp functions on overflow Signed-off-by: Jaroslav Kysela --- 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;