]> git.alsa-project.org Git - tinycompress.git/commitdiff
lib: return -ERANGE for hpointer/tstamp functions on overflow
authorJaroslav Kysela <perex@perex.cz>
Fri, 29 May 2026 10:57:31 +0000 (12:57 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 29 May 2026 10:57:31 +0000 (12:57 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/tinycompress/tinycompress.h
src/lib/compress.c

index 74a7167572586450ada73d915eb9556bd89b6dda..2fb6b0b2ac47a6b88779652213955a5a37acd8e7 100644 (file)
@@ -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
index d73b171d91507aa2d0299ce76f381eab39a75196..bc41afc613932c2b55052b9519bfeca47d760594 100644 (file)
@@ -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;